Index: openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl 22 Jul 2018 11:37:20 -0000 1.10 +++ openacs-4/packages/acs-templating/tcl/test/parse-test-procs.tcl 3 Sep 2024 15:37:35 -0000 1.11 @@ -1,117 +1,364 @@ ad_library { - + Tests for adp parsing - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2005-01-01 @cvs-id $Id$ } aa_register_case \ + -cats { + api + production_safe + } \ -procs { + template::adp_variable_regexp + template::adp_variable_regexp_noquote + template::adp_variable_regexp_noi18n + template::adp_variable_regexp_literal template::adp_array_variable_regexp template::adp_array_variable_regexp_noquote + template::adp_array_variable_regexp_noi18n + template::adp_array_variable_regexp_literal } \ template_variable { - test adp variable parsing procedures -} { - aa_run_with_teardown \ - -test_code { - set code "=@test_array.test_key@" - aa_true "Regular array var name detected" [regexp [template::adp_array_variable_regexp] $code discard pre arr var] - aa_equals "Preceding char is '${pre}'" "=" $pre - aa_equals "Array name is '${arr}'" \ - "test_array" $arr - aa_equals "Variable name is '${var}'" \ - "test_key" $var + test adp variable parsing procedures + } { + aa_section "Testing plain variable" - set code "=@formerror.test_array.test_key@" - aa_true "Formerror regular array var name detected" [regexp [template::adp_array_variable_regexp] $code discard pre arr var] + set code "=@test_var@" + aa_true "Variable detected" \ + [regexp [template::adp_variable_regexp] $code discard pre var] + aa_equals "Preceding char is '${pre}'" "=" $pre + aa_equals "Variable name is '${var}'" \ + "test_var" $var + + set code "=@test_array.test_key@" + aa_true "Regular array var name detected" \ + [regexp [template::adp_array_variable_regexp] $code discard pre arr var] + aa_equals "Preceding char is '${pre}'" "=" $pre + aa_equals "Array name is '${arr}'" \ + "test_array" $arr + aa_equals "Variable name is '${var}'" \ + "test_key" $var + + set code "=@formerror.test_array.test_key@" + aa_true "Formerror regular array var name detected" \ + [regexp [template::adp_array_variable_regexp] $code discard pre arr var] + aa_equals "Preceding char is '${pre}'" "=" $pre + aa_equals "Array name is '${arr}'" \ + "formerror" $arr + aa_equals "Variable name is '${var}'" \ + "test_array.test_key" $var + + foreach modifier {noquote literal noi18n} { + aa_section "Testing ;$modifier modifier" + + set code "=@test_var;$modifier@" + aa_true "Variable detected" \ + [regexp [template::adp_variable_regexp_$modifier] $code discard pre var] aa_equals "Preceding char is '${pre}'" "=" $pre - aa_equals "Array name is '${arr}'" \ - "formerror" $arr aa_equals "Variable name is '${var}'" \ - "test_array.test_key" $var + "test_var" $var - set code "=@test_array.test_key;noquote@" - aa_true "Noquote array var name detected" [regexp [template::adp_array_variable_regexp_noquote] $code discard pre arr var] + set code "=@test_array.test_key;$modifier@" + aa_true "$modifier array var name detected" \ + [regexp [template::adp_array_variable_regexp_$modifier] $code discard pre arr var] aa_equals "Preceding char is '${pre}'" "=" $pre aa_equals "Array name is '${arr}'" \ "test_array" $arr aa_equals "Variable name is '${var}'" \ "test_key" $var - set code "=@formerror.test_array.test_key;noquote@" - aa_true "Noquote formerror array var name detected" [regexp [template::adp_array_variable_regexp_noquote] $code discard pre arr var] + set code "=@formerror.test_array.test_key;$modifier@" + aa_true "$modifier formerror array var name detected" \ + [regexp [template::adp_array_variable_regexp_$modifier] $code discard pre arr var] aa_equals "Preceding char is '${pre}'" "=" $pre aa_equals "Array name is '${arr}'" \ "formerror" $arr aa_equals "Variable name is '${var}'" \ "test_array.test_key" $var - - } -} + } -aa_register_case -cats {api smoke} tcl_to_sql_list { - Tests the tcl_to_sql_list proc. +aa_register_case \ + -cats {api smoke production_safe} \ + -procs { + template::expand_percentage_signs + } \ + expand_percentage_signs { + Test expand percentage signs to make sure it substitutes correctly - @author Torben Brosten -} { - aa_equals "parses list of 0 items" [template::util::tcl_to_sql_list [list]] "" - aa_equals "parses list of 2 or more" \ - [template::util::tcl_to_sql_list [list isn't hess' 'bit 'trippy']] \ - "'isn''t', 'hess''', '''bit', '''trippy'''" + @author Dave Bauer + @creation-date 2005-11-20 + } { + set orig_message "Test message %one%" + set one "\[__does_not_exist__\]" + set message $orig_message -} + aa_false "Expanded square bracket text" \ + [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] + aa_log $errmsg + aa_equals "square brackets safe" $expanded_message "Test message \[__does_not_exist__\]" + set one "\$__does_not_exist" + aa_false "Expanded dollar test" \ + [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] + aa_log $errmsg + aa_equals "dollar sign safe" $expanded_message "Test message \$__does_not_exist" + + set one "\$two(\$three(\[__does_not_exist\]))" + + aa_false "Square bracket in array key test" \ + [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] + aa_log $errmsg + aa_equals "square brackets in array key safe" \ + $expanded_message "Test message \$two(\$three(\[__does_not_exist\]))" + + } + aa_register_case \ - -cats {api smoke} \ + -cats {api smoke production_safe} \ -procs { - template::expand_percentage_signs + ::template::adp_parse_tags + ::template::adp_compile_chunk + ::template::icon + ::template::adp_append_code } \ - expand_percentage_signs { - Test expand percentage signs to make sure it substitutes correctly - - @author Dave Bauer - @creation-date 2005-11-20 -} { - set orig_message "Test message %one%" - set one "\[__does_not_exist__\]" - set message $orig_message + adp_parse_tags { - aa_false "Expanded square bracket text" [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] - aa_log $errmsg - aa_equals "square brackets safe" $expanded_message "Test message \[__does_not_exist__\]" - - set one "\$__does_not_exist" - aa_false "Expanded dollar test" [catch {set expanded_message [template::expand_percentage_signs $message]} errmsg] - aa_log $errmsg - aa_equals "dollar sign safe" $expanded_message "Test message \$__does_not_exist" + Checks the helper template::adp_parse_tags, which performs a + subset of template::adp_compile. - set one "\$two(\$three(\[__does_not_exist\]))" + } { + set HTML {
foo foo @a@