\input regression-test.tex
\documentclass{article}
\usepackage{osgstyler}

\DeclareOsgColorPalette{modern}{
  primary    = {model=HTML, value=2B3A67},
  secondary  = {model=HTML, value=496A81},
  accent     = {model=HTML, value=66999B},
  text       = {model=HTML, value=333333},
  background = {model=HTML, value=FFFFFF},
  structure  = {alias=primary},
  alert      = {model=HTML, value=B00020},
  example    = {model=HTML, value=166534}
}

\DeclareOsgColorPalette{minimal}{
  primary = {model=rgb, value={0.2,0.2,0.7}}
}

% Alias-cycle protection must resolve to empty rather than hang or
% crash. Resolved before \START so the resulting error message does
% not become part of the diffed log.
\DeclareOsgColorPalette{cyclic}{
  primary   = {model=RGB, value={1,1,1}},
  secondary = {alias=accent},
  accent    = {alias=secondary}
}
\ExplSyntaxOn
\tl_new:N \g_test_cyclic_secondary_tl
\OsgColorPaletteResolvedSlotTo{cyclic}{secondary}\l_tmpa_tl
\tl_gset:Nx \g_test_cyclic_secondary_tl {\l_tmpa_tl}
\ExplSyntaxOff

% incomplete-color-resource / conflicting-color-resource must not
% record a resource or alias for the offending slot. Declared before
% \START for the same reason as the cyclic palette above.
\DeclareOsgColorPalette{malformed}{
  primary   = {model=RGB, value={1,1,1}},
  secondary = {model=RGB},
  accent    = {model=RGB, value={1,1,1}, alias=primary}
}

% unknown-color-slot: resolving a slot name outside the portable set
% must fail cleanly (empty result), not crash. Also triggered before
% \START.
\ExplSyntaxOn
\tl_new:N \g_test_unknown_color_slot_tl
\OsgColorPaletteResolvedSlotTo{modern}{bogus}\l_tmpa_tl
\tl_gset:Nx \g_test_unknown_color_slot_tl {\l_tmpa_tl}
\ExplSyntaxOff

\begin{document}
\UseOsgColorPalette{modern}
\START
\ExplSyntaxOn
\OsgColorPaletteResolvedSlotTo{modern}{structure}\l_tmpa_tl
\TYPE{modern-structure=\l_tmpa_tl}
\OsgColorPaletteResolvedSlotTo{minimal}{secondary}\l_tmpa_tl
\TYPE{minimal-secondary=\l_tmpa_tl}
\OsgColorPaletteResolvedSlotTo{minimal}{accent}\l_tmpa_tl
\TYPE{minimal-accent=\l_tmpa_tl}
\OsgColorPaletteResolvedSlotTo{minimal}{alert}\l_tmpa_tl
\TYPE{minimal-alert=\l_tmpa_tl}
\TYPE{cyclic-secondary-empty=\tl_if_empty:NTF\g_test_cyclic_secondary_tl{yes}{no}}
\TYPE{malformed-secondary-kind=\OsgColorPaletteValue{malformed}{secondary}{kind}}
\TYPE{malformed-accent-kind=\OsgColorPaletteValue{malformed}{accent}{kind}}
\TYPE{unknown-color-slot-empty=\tl_if_empty:NTF\g_test_unknown_color_slot_tl{yes}{no}}
\ExplSyntaxOff
\TYPE{active=\OsgActiveColorPalette}
\TYPE{name=\OsgColorName{structure}}
\TYPE{primary-model=\OsgColorPaletteValue{modern}{primary}{model}}
\TYPE{primary-spec=\OsgColorPaletteValue{modern}{primary}{value}}
\extractcolorspec{osgstyler-structure}\TestColor
\TYPE{structure-color=\TestColor}
\extractcolorspec{osgstyler-alert}\TestColor
\TYPE{alert-color=\TestColor}
\END
\end{document}
