Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 3 Dec 2002 17:27:04 -0000 1.1
+++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 4 Apr 2003 09:47:43 -0000 1.2
@@ -1,5 +1,5 @@
ad_library {
- Test TCL procedures in the acs-lang package with acs-automated-testing.
+ Helper test Tcl procedures.
@author Peter Marklund (peter@collaboraid.biz)
@creation-date 18 October 2002
@@ -16,205 +16,3 @@
return "[acs_package_root_dir acs-lang]/tcl/test"
}
}
-
-aa_register_case util__replace_temporary_tags_with_lookups {
- Primarily tests lang::util::replace_temporary_tags_with_lookups,
- Also tests the procs lang::catalog::export_messages_to_file, lang::catalog::parse,
- lang::catalog::read_file, and lang::util::get_temporary_tags_indices.
-
- A test tcl file and catalog file are created. The temporary tags in the
- tcl file are replaced with message lookups and keys and messages are appended
- to the catalog file.
-
- @author Peter Marklund (peter@collaboraid.biz)
- @creation-date 18 October 2002
-} {
- # The files involved in the test
- set test_dir [lang::test::get_dir]
- set catalog_file "${test_dir}/acs-lang.en_US.ISO-8859-1.xml"
- set backup_file_suffix ".orig"
- set catalog_backup_file "${catalog_file}${backup_file_suffix}"
- regexp {^.*(packages/.*)$} $test_dir match test_dir_rel
- set tcl_file "${test_dir_rel}/test-message-tags.tcl"
- set tcl_backup_file "${tcl_file}${backup_file_suffix}"
-
- # The test messages to use for the catalog file
- array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3]
-
- # Write the test tcl file
- set tcl_file_id [open "[acs_root_dir]/$tcl_file" w]
- set new_key_1 "_"
- set new_text_1 "Auto Key"
- set new_key_2 "key_1"
- set new_text_2 "text_1_different"
- set new_key_3 "key_1"
- set new_text_3 "$messages_array(key_1)"
- puts $tcl_file_id "# The following key should be auto-generated and inserted
- # <#${new_key_1} ${new_text_1}#>
- #
- # The following key should be made unique and inserted
- # <#${new_key_2} ${new_text_2}#>
- #
- # The following key should not be inserted in the message catalog
- # <#${new_key_3} ${new_text_3}#>"
- close $tcl_file_id
-
- # Write the catalog file
- lang::catalog::export_messages_to_file $catalog_file [array get messages_array]
-
- # Replace message tags in the tcl file and insert into catalog file
- lang::util::replace_temporary_tags_with_lookups -catalog_file_path $catalog_file $tcl_file
-
- # Read the contents of the catalog file
- array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]]
- array set updated_messages_array [lindex [array get catalog_array messages] 1]
-
- # Assert that the old messages are unchanged
- foreach old_message_key [array names messages_array] {
- aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \
- $updated_messages_array($old_message_key)]
- }
-
- # Check that the first new key was autogenerated
- ns_log Notice "auto key compare \"$updated_messages_array(Auto_Key)\" - \"$new_text_1\""
- aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1]
-
- # Check that the second new key was made unique and inserted
- aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2]
-
- # Check that the third key was not inserted
- aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \
- $messages_array($new_key_3)]
-
- # Check that there are no tags left in the tcl file
- set tcl_file_id [open "[acs_root_dir]/$tcl_file" r]
- set updated_tcl_contents [read $tcl_file_id]
- close $tcl_file_id
- aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0]
-
- # Delete the catalog files
- file delete $catalog_backup_file
- file delete $catalog_file
-
- # Delete the tcl files
- file delete "[acs_root_dir]/$tcl_file"
- file delete "[acs_root_dir]/$tcl_backup_file"
-}
-
-aa_register_case util__get_hash_indices {
- Tests the lang::util::get_hash_indices proc
-
- @author Peter Marklund (peter@collaboraid.biz)
- @creation-date 21 October 2002
-} {
- set multilingual_string "#package1.key1# abc\# #package2.key2#"
- set indices_list [lang::util::get_hash_indices $multilingual_string]
- set expected_indices_list [list [list 0 14] [list 21 35]]
-
- aa_true "there should be two hash entries" [expr [llength $indices_list] == 2]
-
- set counter 0
- foreach index_item $indices_list {
- set expected_index_item [lindex $expected_indices_list $counter]
-
- aa_true "checking start and end indices of item $counter" \
- [expr [string equal [lindex $index_item 0] [lindex $expected_index_item 0]] && \
- [string equal [lindex $index_item 1] [lindex $expected_index_item 1]]]
-
- set counter [expr $counter + 1]
- }
-}
-
-aa_register_case util__convert_adp_variables_to_percentage_signs {
- Tests the lang::util::convert_adp_variables_to_percentage_signs proc.
-
- @author Peter Marklund (peter@collaboraid.biz)
- @creation-date 25 October 2002
-} {
- set adp_chunk "@array.variable_name@ @variable_name2@ peter@collaboraid.biz"
-
- set adp_chunk_converted [lang::util::convert_adp_variables_to_percentage_signs $adp_chunk]
- set adp_chunk_expected "%array.variable_name% %variable_name2% peter@collaboraid.biz"
-
- aa_true "adp vars should be subsituted with percentage sings" [string equal $adp_chunk_converted \
- $adp_chunk_expected]
-
- # Test that a string can start with adp vars
- set adp_chunk "@first_names@ @last_name@ peter@collaboraid.biz"
- set adp_chunk_converted [lang::util::convert_adp_variables_to_percentage_signs $adp_chunk]
- set adp_chunk_expected "%first_names% %last_name% peter@collaboraid.biz"
- aa_true "adp vars should be subsituted with percentage sings" [string equal $adp_chunk_converted \
- $adp_chunk_expected]
-}
-
-aa_register_case util__replace_adp_text_with_message_tags {
- Test the lang::util::replace_adp_text_with_message_tags proc.
-
- @author Peter Marklund (peter@collaboraid.biz)
- @creation-date 28 October 2002
-} {
- # File paths used
- set adp_file_path "[lang::test::get_dir]/adp_tmp_file.adp"
-
- # Write the adp test file
- set adp_file_id [open $adp_file_path w]
- puts $adp_file_id "
-@first_names@ @last_name@ peter@collaboraid.biz
-@context_bar@
-Test text"
- close $adp_file_id
-
- # Do the substitutions
- lang::util::replace_adp_text_with_message_tags $adp_file_path "write"
-
- # Read the changed test file
- set adp_file_id [open $adp_file_path r]
- set adp_contents [read $adp_file_id]
- close $adp_file_id
-
- set expected_adp_pattern {
-<#[a-zA-Z_]+ %first_names% %last_name% peter@collaboraid.biz#>
-@context_bar@
-<#[a-zA-Z_]+ Test text\s*}
-
- ns_log Notice "adp_contents $adp_contents"
-
- # Assert proper replacements have been done
- aa_true "replacing adp text with tags" \
- [regexp $expected_adp_pattern $adp_contents match]
-
- # Remove the adp test file
- file delete $adp_file_path
-}
-
-aa_register_case message__format {
- Tests the lang::message::format proc
-
- @author Peter Marklund (peter@collaboraid.biz)
- @creation-date 21 October 2002
-} {
-
- set localized_message "The %frog% jumped across the %fence%. About 50% of the time, he stumbled, or maybe it was %%20 %times%."
- set value_list {frog frog fence fence}
-
- set subst_message [lang::message::format $localized_message $value_list]
- set expected_message "The frog jumped across the fence. About 50% of the time, he stumbled, or maybe it was %20 %times%."
-
- aa_true "the frog should jump across the fence" [string equal $subst_message \
- $expected_message]
-}
-
-aa_register_case message__get_missing_embedded_vars {
- Tests the lang::message::get_missing_embedded_vars proc
-
- @author Peter Marklund (peter@collaboraid.biz)
- @creation-date 12 November 2002
-} {
- set en_us_message "this is a message with some %vars% and some more %variables%"
- set new_message "this message contains no vars"
-
- set missing_vars_list [lang::message::get_missing_embedded_vars $en_us_message $new_message]
-
- aa_true "check the missing vars" [expr [string equal [lindex $missing_vars_list 0] "vars"] && \
- [string equal [lindex $missing_vars_list 1] "variables"]]
-}