[SCM] Lisaac compiler branch, master, updated. 8a95a9037204db4637f632201aeae1d16bf20a60

Jeremy Cowgar jeremy at cowgar.com
Thu Mar 26 02:20:51 UTC 2009


The following commit has been merged in the master branch:
commit 794aafeee6eb0da0c7644cebcceddddb28cd1ab0
Author: Jeremy Cowgar <jeremy at cowgar.com>
Date:   Wed Mar 25 21:51:21 2009 -0400

    * Added verbose flag to unit testing.
    * Added command line handling for unit tests to automatically
      configure the unit tests per given command line options.
    * Defaulted verbose option to FALSE as not to be inundated with
      useless passed messages, allows you to see only whats failing.
    * Simplified greatly the test_* slots.
    * Fixed TAB indentation on files I recently committed.
    * Added .gitignore files for bin and tests directories.

diff --git a/bin/.gitignore b/bin/.gitignore
new file mode 100644
index 0000000..77d8bee
--- /dev/null
+++ b/bin/.gitignore
@@ -0,0 +1,4 @@
+lisaac
+shorter
+lisaac.exe
+shorter.exe
diff --git a/lib/testing/unit_test.li b/lib/testing/unit_test.li
index d854c42..3d180aa 100644
--- a/lib/testing/unit_test.li
+++ b/lib/testing/unit_test.li
@@ -1,124 +1,240 @@
+///////////////////////////////////////////////////////////////////////////////
+//                             Lisaac Library                                //
+//                                                                           //
+//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
+//                                                                           //
+//   This program is free software: you can redistribute it and/or modify    //
+//   it under the terms of the GNU General Public License as published by    //
+//   the Free Software Foundation, either version 3 of the License, or       //
+//   (at your option) any later version.                                     //
+//                                                                           //
+//   This program is distributed in the hope that it will be useful,         //
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
+//   GNU General Public License for more details.                            //
+//                                                                           //
+//   You should have received a copy of the GNU General Public License       //
+//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
+//                                                                           //
+//                     http://isaacproject.u-strasbg.fr/                     //
+///////////////////////////////////////////////////////////////////////////////
+
 Section Header
 
-	+ name := UNIT_TEST;
+  + name := UNIT_TEST;
+
+  - copyright := "2009 Jeremy Cowgar";
+
+  - comment := "Unit testing framework for Lisaac";
+
+Section Inherit
+
+  - parent_object:OBJECT := OBJECT;
 
 Section Private
 
-	+ pass_count:REAL_32 := 0;
-	+ fail_count:REAL_32 := 0;
+  + pass_count:REAL_32 := 0;
+  + fail_count:REAL_32 := 0;
+  + verbose:BOOLEAN := FALSE;
+  + suite_name:ABSTRACT_STRING;
+  + section_name:ABSTRACT_STRING;
+
+  - usage <-
+  // Display common usage message on console
+  (
+    ("Usage: " + (COMMAND_LINE.item 0) + " [-v]").printline;
+    "  -v    verbose reporting".println;
+    OBJECT.die_with_code 1;
+  );
+
+  - bar <-
+  // Print a double line bar for visual separation.
+  (
+    "\n==============================\n".print;
+  );
+
+  - minibar <-
+  // Print a single line bar for visual separation.
+  (
+    "\n   ---------------------------\n".print;
+  );
 
-	- bar <-
-	(
-		"\n==============================\n".print;
-	);
+Section Public
+  // Setup
+
+  - init <-
+  // Initialize unit testing. This currently looks for
+  // command line parameters and configures itself
+  // accordingly.
+  (
+    + arg:ABSTRACT_STRING;
+
+    1.to (COMMAND_LINE.count-1) do { idx:INTEGER;
+      arg := (COMMAND_LINE.item idx);
+
+      (arg == "-v").if {
+        set_verbose TRUE;
+      } else {
+        usage;
+      };
+    };
+  );
+
+  - set_verbose verbose_mode:BOOLEAN <-
+  // When verbose is true, suite names, section names, passed and
+  // failed tests will all be reported. When verbose is false, only
+  // failed tests will be reported.
+  (
+    verbose := verbose_mode;
+  );
 
-	- minibar <-
-	(
-		"\n   ---------------------------\n".print;
-	);
+Section Public
+  // Sectioning
+
+  - suite name:ABSTRACT_STRING <-
+  // Set the major suite name
+  (
+    suite_name := name;
+
+    verbose.if {
+      ("\n" + name).print;
+      bar;
+    };
+  );
+
+  - section name:ABSTRACT_STRING <-
+  // Set the minor section of a suite
+  (
+    section_name := name;
+
+    verbose.if {
+      ("\n   " + name).print;
+      minibar;
+    };
+  );
 
 Section Public
+  // Tests
+
+  - test_failed name:ABSTRACT_STRING <-
+  // Fail a test with no data report
+  (
+    fail_count := fail_count + 1;
+
+    (verbose = FALSE).if {
+      (suite_name + ":" + section_name + " -> ").print;
+    } else {
+      "   ".print;
+    };
+
+    (name + "... failed, no data given\n").print;
+  );
+
+  - test_failed name:ABSTRACT_STRING got got:ABSTRACT_STRING expected expected:ABSTRACT_STRING <-
+  // Fail a test
+  (
+    fail_count := fail_count + 1;
+
+    (verbose = FALSE).if {
+      (suite_name + ":" + section_name + " -> ").print;
+    } else {
+      "   ".print;
+    };
+
+    (name + "... failed: expected '" + expected + "' got '" + got + "'\n").print;
+  );
+
+  - test_passed name:ABSTRACT_STRING <-
+  // Pass a test
+  (
+    pass_count := pass_count + 1;
+
+    verbose.if {
+      ("   " + name + "... passed\n").print;
+    };
+  );
+
+  - test name:ABSTRACT_STRING integer got:INTEGER equals expected:INTEGER <-
+  // Test equality between two INTEGER values, fail on not equal
+  (
+    (expected = got).if {
+      test_passed name;
+    } else {
+      test_failed name got (got.to_string) expected (expected.to_string);
+    };
+  );
+
+  - test name:ABSTRACT_STRING real_16_16 got:REAL_16_16 equals expected:REAL_16_16 <-
+  // Test equality between two REAL_16_16 values, fail on not equal
+  (
+    (expected = got).if {
+      test_passed name;
+    } else {
+      test_failed name got (got.to_string) expected (expected.to_string);
+    }
+  );
+
+  - test name:ABSTRACT_STRING boolean got:BOOLEAN equals expected:BOOLEAN <-
+  // Test equality between two BOOLEAN values, fail on not equal
+  (
+    (got = expected).if {
+      test_passed name;
+    } else {
+      test_failed name got (got.to_string) expected (expected.to_string);
+    };
+  );
+
+  - test name:ABSTRACT_STRING character got:CHARACTER equals expected:CHARACTER <-
+  // Test equality between two CHARACTER values, fail on not equal
+  (
+    (got = expected).if {
+      test_passed name;
+    } else {
+      //test_failed name got (got.to_string) expected (expected.to_string);
+    };
+  );
+
+  - test name:ABSTRACT_STRING string got:ABSTRACT_STRING equals expected:ABSTRACT_STRING <-
+  // Test equality between two STRING values, fail on not equal
+  (
+    (got == expected).if {
+      test_passed name;
+    } else {
+      test_failed name got got expected expected;
+    };
+  );
 
-	- suite name:ABSTRACT_STRING <-
-	(
-		("\n" + name).print;
-		bar;
-	);
-
-	- section name:ABSTRACT_STRING <-
-	(
-		("\n   " + name).print;
-		minibar;
-	);
-
-	- test name:ABSTRACT_STRING integer value:INTEGER equals expect:INTEGER <-
-	(
-		("   " + name + "... ").print;
-		(expect = value).if {
-			pass_count := pass_count + 1.0;
-			"passed\n".print;
-		} else {
-			fail_count := fail_count + 1.0;
-			"failed: expected '".print;
-			expect.print;
-			"' got '".print;
-			value.print;
-		 "'\n".print;
-		};
-	);
-
-	- test name:ABSTRACT_STRING real_16_16 value:REAL_16_16 equals expect:REAL_16_16 <-
-	(
-		("   " + name + "... ").print;
-		(expect = value).if {
-			pass_count := pass_count + 1.0;
-			"passed\n".print;
-		} else {
-			fail_count := fail_count + 1.0;
-			"failed: expected '".print;
-			expect.print;
-			"' got '".print;
-			value.print;
-		 "'\n".print;
-		};
-	);
-
-	- test name:ABSTRACT_STRING boolean value:BOOLEAN equals expect:BOOLEAN <-
-	(
-		("   " + name + "... ").print;
-		(value = expect).if {
-			pass_count := pass_count + 1.0;
-			"passed\n".print;
-		} else {
-			fail_count := fail_count + 1.0;
-			"failed: expected '".print;
-			expect.print;
-			"' got '".print;
-			value.print;
-			"'\n".print;
-		};
-	);
-
-	- test name:ABSTRACT_STRING character value:CHARACTER equals expect:CHARACTER <-
-	(
-		("   " + name + "... ").print;
-		(value = expect).if {
-			pass_count := pass_count + 1.0;
-			"passed\n".print;
-		} else {
-			fail_count := fail_count + 1.0;
-			"failed: expected '".print;
-			expect.print;
-			"' got '".print;
-			value.print;
-			"'\n".print;
-		};
-	);
-
-	- test name:ABSTRACT_STRING string value:ABSTRACT_STRING equals expect:ABSTRACT_STRING <-
-	(
-		("   " + name + "... ").print;
-		((expect.compare value) = 0).if {
-			pass_count := pass_count + 1.0;
-			"passed\n".print;
-		} else {
-			fail_count := fail_count + 1.0;
-			("failed: expected '" + expect + "' got '" + value + "'\n").print;
-		};
-	);
-
-	- test_results <-
-	(
-		+ total:REAL_32;
-		+ success:REAL_32;
-
-		total := pass_count + fail_count;
-		success := pass_count / total;
-
-		"\nResults".print;
-		bar;
-		"  Passed: ".print; pass_count.to_integer.print; "\n".print;
-		"  Failed: ".print; fail_count.to_integer.print; "\n".print;
-		"   Total: ".print; total.to_integer.print; "\n".print;
-		" Success: ".print; (success * 100).to_integer.print; "%\n".print;
-	);
+Section Public
+  // Reporting
+
+  - test_results <-
+  // Print the test results to the screen. If fail_count > 0 then
+  // the program will exit with an error level of 1.
+  (
+    + total:REAL_32;
+    + success:REAL_32;
+
+    total := pass_count + fail_count;
+    success := pass_count / total;
+
+    verbose.if {
+      "\nResults".print;
+      bar;
+      "  Passed: ".print; pass_count.to_integer.print; "\n".print;
+      "  Failed: ".print; fail_count.to_integer.print; "\n".print;
+      "   Total: ".print; total.to_integer.print; "\n".print;
+      " Success: ".print; (success * 100).to_integer.print; "%\n".print;
+    } else {
+      (
+        "\n" +
+        "Pass: " + pass_count.to_integer.to_string +
+        " Fail: " + fail_count.to_integer.to_string +
+        " Total: " + total.to_integer.to_string +
+        " Success: " + (success * 100).to_integer.to_string + "%\n"
+      ).print;
+    };
+
+    (fail_count > 0).if {
+      OBJECT.die_with_code 1;
+    };
+  );
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..44890cc
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,3 @@
+lib_tests
+lib_tests.c
+lib_tests.exe
diff --git a/tests/abstract_string_test.li b/tests/abstract_string_test.li
index 1d3c0e9..5f25f2f 100644
--- a/tests/abstract_string_test.li
+++ b/tests/abstract_string_test.li
@@ -1,200 +1,225 @@
+///////////////////////////////////////////////////////////////////////////////
+//                             Lisaac Library                                //
+//                                                                           //
+//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
+//                                                                           //
+//   This program is free software: you can redistribute it and/or modify    //
+//   it under the terms of the GNU General Public License as published by    //
+//   the Free Software Foundation, either version 3 of the License, or       //
+//   (at your option) any later version.                                     //
+//                                                                           //
+//   This program is distributed in the hope that it will be useful,         //
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
+//   GNU General Public License for more details.                            //
+//                                                                           //
+//   You should have received a copy of the GNU General Public License       //
+//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
+//                                                                           //
+//                     http://isaacproject.u-strasbg.fr/                     //
+///////////////////////////////////////////////////////////////////////////////
+
 Section Header
 
-	+ name := ABSTRACT_STRING_TEST;
+  + name := ABSTRACT_STRING_TEST;
+
+  - copyright := "2009 Jeremy Cowgar";
+
+  - comment := "Test suite for ABSTRACT_STRING.";
 
 Section Public
 
-	- run <-
-	(
-		+ name:ABSTRACT_STRING;
-		+ empty:ABSTRACT_STRING;
-		+ values:ARRAY[STRING];
-
-		name := "John Doe";
-		empty := "";
-
-		UNIT_TEST.suite "ABSTRACT_STRING";
-
-		UNIT_TEST.section "basic";
-		UNIT_TEST.test "count #1" integer (name.count) equals 8;
-		UNIT_TEST.test "count #2" integer (empty.count) equals 0;
-		UNIT_TEST.test "lower #1" integer (name.lower) equals 1;
-		UNIT_TEST.test "lower #2" integer (empty.lower) equals 1;
-		UNIT_TEST.test "upper #1" integer (name.upper) equals 8;
-		UNIT_TEST.test "upper #2" integer (empty.upper) equals 0;
-
-		UNIT_TEST.section "Access";
-		UNIT_TEST.test "item #1" character (name.item 1) equals 'J';
-		UNIT_TEST.test "item #2" character (name.item 2) equals 'o';
-		UNIT_TEST.test "item #3" character (name.item 3) equals 'h';
-
-		UNIT_TEST.section "Testing";
-		UNIT_TEST.test "valid_index #1" boolean (name.valid_index 0) equals FALSE;
-		UNIT_TEST.test "valid_index #2" boolean (name.valid_index 1) equals TRUE;
-		UNIT_TEST.test "valid_index #3" boolean (name.valid_index 2) equals TRUE;
-		UNIT_TEST.test "valid_index #4" boolean (name.valid_index 3) equals TRUE;
-		UNIT_TEST.test "valid_index #5" boolean (name.valid_index 40) equals FALSE;
-		UNIT_TEST.test "valid_index #6" boolean (empty.valid_index 1) equals FALSE;
-		UNIT_TEST.test "valid_index #7" boolean (empty.valid_index 2) equals FALSE;
-		UNIT_TEST.test "is_empty #1" boolean (name.is_empty) equals FALSE;
-		UNIT_TEST.test "is_empty #2" boolean (empty.is_empty) equals TRUE;
-		UNIT_TEST.test "hash_code #1" integer (name.hash_code) equals 7915731; // TODO: is correct?
-		UNIT_TEST.test "hash_code #2" integer ("ABC".hash_code) equals 2022;   // TODO: is correct?
-		UNIT_TEST.test "has #1" boolean (name.has 'o') equals TRUE;
-		UNIT_TEST.test "has #2" boolean (name.has 'D') equals TRUE;
-		UNIT_TEST.test "has #3" boolean (name.has '8') equals FALSE;
-		UNIT_TEST.test "has #4" boolean (name.has 'x') equals FALSE;
-		UNIT_TEST.test "has #5" boolean (name.has 'd') equals FALSE;
-		UNIT_TEST.test "has_substring #1" boolean (name.has_substring "Doe") equals TRUE;
-		UNIT_TEST.test "has_substring #2" boolean (name.has_substring "John") equals TRUE;
-		UNIT_TEST.test "has_substring #3" boolean (name.has_substring "hn D") equals TRUE;
-		UNIT_TEST.test "has_substring #4" boolean (name.has_substring "e") equals TRUE;
-		UNIT_TEST.test "has_substring #5" boolean (name.has_substring "Jeff") equals FALSE;
-		UNIT_TEST.test "has_substring #6" boolean (name.has_substring "10") equals FALSE;
-		UNIT_TEST.test "occurrences #1" integer (name.occurrences  'o') equals 2;
-		UNIT_TEST.test "occurrences #2" integer (name.occurrences  'h') equals 1;
-		UNIT_TEST.test "occurrences #3" integer (name.occurrences  'X') equals 0;
-		UNIT_TEST.test "occurrences #4" integer (empty.occurrences  'X') equals 0;
-		UNIT_TEST.test "has_suffix #1" boolean (name.has_suffix "Doe") equals TRUE;
-		UNIT_TEST.test "has_suffix #2" boolean (name.has_suffix "oe") equals TRUE;
-		UNIT_TEST.test "has_suffix #3" boolean (name.has_suffix "e") equals TRUE;
-		UNIT_TEST.test "has_suffix #4" boolean (name.has_suffix "Smith") equals FALSE;
-		UNIT_TEST.test "has_suffix #5" boolean (name.has_suffix "o") equals FALSE;
-		UNIT_TEST.test "has_suffix #6" boolean (empty.has_suffix "Bye") equals FALSE;
-		UNIT_TEST.test "has_prefix #1" boolean (name.has_prefix "John") equals TRUE;
-		UNIT_TEST.test "has_prefix #2" boolean (name.has_prefix "Joh") equals TRUE;
-		UNIT_TEST.test "has_prefix #3" boolean (name.has_prefix "Jo") equals TRUE;
-		UNIT_TEST.test "has_prefix #4" boolean (name.has_prefix "J") equals TRUE;
-		UNIT_TEST.test "has_prefix #5" boolean (name.has_prefix "Jeff") equals FALSE;
-		UNIT_TEST.test "has_prefix #6" boolean (empty.has_prefix "Jack") equals FALSE;
-
-		UNIT_TEST.section "Testing/Conversion";
-		UNIT_TEST.test "is_boolean #1" boolean ("TRUE".is_boolean) equals TRUE;
-		UNIT_TEST.test "is_boolean #2" boolean ("FALSE".is_boolean) equals TRUE;
-		UNIT_TEST.test "is_boolean #3" boolean ("John".is_boolean) equals FALSE;
-		UNIT_TEST.test "is_boolean #4" boolean ("".is_boolean) equals FALSE;
-		UNIT_TEST.test "to_boolean #1" boolean ("TRUE".to_boolean) equals TRUE;
-		UNIT_TEST.test "to_boolean #2" boolean ("FALSE".to_boolean) equals FALSE;
-		UNIT_TEST.test "is_integer #1" boolean ("10".is_integer) equals TRUE;
-		UNIT_TEST.test "is_integer #2" boolean ("1029".is_integer) equals TRUE;
-		UNIT_TEST.test "is_integer #3" boolean ("-110".is_integer) equals TRUE;
-		UNIT_TEST.test "is_integer #4" boolean ("+110".is_integer) equals TRUE;
-		UNIT_TEST.test "is_integer #5" boolean ("Jack".is_integer) equals FALSE;
-		UNIT_TEST.test "is_integer #6" boolean ("".is_integer) equals FALSE;
-		UNIT_TEST.test "is_integer #7" boolean ("100.44".is_integer) equals FALSE;
-		UNIT_TEST.test "to_integer #1" integer ("100".to_integer) equals 100;
-		UNIT_TEST.test "to_integer #2" integer ("-12".to_integer) equals (-12);
-		UNIT_TEST.test "to_integer #3" integer ("0".to_integer) equals 0;
-		UNIT_TEST.test "is_hexadecimal #1" boolean ("16AF".is_hexadecimal) equals TRUE;
-		UNIT_TEST.test "is_hexadecimal #2" boolean ("10".is_hexadecimal) equals TRUE;
-		UNIT_TEST.test "is_hexadecimal #3" boolean ("16ZC".is_hexadecimal) equals FALSE;
-		UNIT_TEST.test "to_hexadecimal #1" integer ("16AF".to_hexadecimal) equals 5807;
-		UNIT_TEST.test "to_hexadecimal #2" integer ("10".to_hexadecimal) equals 16;
-		UNIT_TEST.test "is_octal #1" boolean ("5".is_octal) equals TRUE;
-		UNIT_TEST.test "is_octal #2" boolean ("25".is_octal) equals TRUE;
-		UNIT_TEST.test "is_octal #3" boolean ("2AF".is_octal) equals FALSE;
-		UNIT_TEST.test "is_octal #4" boolean ("Jack".is_octal) equals FALSE;
-		UNIT_TEST.test "to_octal #1" integer ("5".to_octal) equals 5;
-		UNIT_TEST.test "to_octal #2" integer ("25".to_octal) equals 21;
-		// TODO: Where is is_binary ?
-		UNIT_TEST.test "to_binary #1" integer ("101".to_binary) equals 5;
-		UNIT_TEST.test "to_binary #2" integer ("10000000101".to_binary) equals 1029;
-		UNIT_TEST.test "is_real_16_16 #1" boolean ("10".is_real_16_16) equals TRUE;
-		UNIT_TEST.test "is_real_16_16 #2" boolean ("-33.1".is_real_16_16) equals TRUE;
-		UNIT_TEST.test "is_real_16_16 #3" boolean ("13FD".is_real_16_16) equals FALSE;
-		UNIT_TEST.test "is_real_16_16 #4" boolean ("+100.39".is_real_16_16) equals TRUE;
-		UNIT_TEST.test "to_real_16_16 #1" real_16_16 ("10".to_real_16_16) equals 10.0;
-		UNIT_TEST.test "to_real_16_16 #2" real_16_16 ("-33.1".to_real_16_16) equals (-33.1);
-
-		UNIT_TEST.section "Indexing";
-		UNIT_TEST.test "item_code #1" integer (name.item_code 1) equals 74;
-		UNIT_TEST.test "item_code #2" integer (name.item_code 2) equals 111;
-		UNIT_TEST.test "item_code #3" integer (name.item_code 3) equals 104;
-		UNIT_TEST.test "index_of since #1" integer (name.index_of 'J' since 1) equals 1;
-		UNIT_TEST.test "index_of since #2" integer (name.index_of 'o' since 1) equals 2;
-		UNIT_TEST.test "index_of since #3" integer (name.index_of 'h' since 1) equals 3;
-		UNIT_TEST.test "index_of since #6" integer (name.index_of 'o' since 4) equals 7;
-		UNIT_TEST.test "index_of since #4" integer (name.index_of 'Z' since 1) equals 9;
-		UNIT_TEST.test "index_of since #5" integer (name.index_of 'J' since 2) equals 9;
-		UNIT_TEST.test "last_index_of since #1" integer (name.last_index_of 'o' since 8) equals 7;
-		UNIT_TEST.test "last_index_of since #2" integer (name.last_index_of 'o' since 5) equals 2;
-		UNIT_TEST.test "fast_index_of #1" integer (name.fast_index_of 'J') equals 1;
-		UNIT_TEST.test "fast_index_of #2" integer (name.fast_index_of 'o') equals 2;
-		UNIT_TEST.test "fast_index_of #3" integer (name.fast_index_of 'h') equals 3;
-		UNIT_TEST.test "fast_index_of #4" integer (name.fast_index_of 'D') equals 6;
-		UNIT_TEST.test "first_index_of #1" integer (name.first_index_of 'o') equals 2;
-		UNIT_TEST.test "first_index_of #2" integer (name.first_index_of 'n') equals 4;
-		UNIT_TEST.test "first_index_of #3" integer (name.first_index_of 'D') equals 6;
-		UNIT_TEST.test "fast_last_index_of #1" integer (name.fast_last_index_of 'e') equals 8;
-		UNIT_TEST.test "fast_last_index_of #2" integer (name.fast_last_index_of 'o') equals 7;
-		UNIT_TEST.test "fast_last_index_of #3" integer (name.fast_last_index_of 'n') equals 4;
-		UNIT_TEST.test "last_index_of #1" integer (name.last_index_of 'J') equals 1;
-		UNIT_TEST.test "last_index_of #2" integer (name.last_index_of 'o') equals 7;
-		UNIT_TEST.test "last_index_of #3" integer (name.last_index_of 'D') equals 6;
-		UNIT_TEST.test "index_of #1" integer (name.index_of 'J') equals 1;
-		UNIT_TEST.test "index_of #2" integer (name.index_of 'o') equals 2;
-		UNIT_TEST.test "index_of #3" integer (name.index_of 'h') equals 3;
-		UNIT_TEST.test "index_of #4" integer (name.index_of 'e') equals 8;
-
-		UNIT_TEST.section "Comparisons";
-		UNIT_TEST.test "equal #1" string "A" equals "A";
-		UNIT_TEST.test "equal #2" string name equals "John Doe";
-		UNIT_TEST.test "equal #3" string empty equals "";
-		UNIT_TEST.test "compare #1" integer (name.compare "Mike Smith") equals (-1);
-		UNIT_TEST.test "compare #2" integer (name.compare "Andy Jones") equals 1;
-		UNIT_TEST.test "compare #3" integer (name.compare "John Doe") equals 0;
-		UNIT_TEST.test "< #1" boolean (name < "ABC") equals FALSE;
-		UNIT_TEST.test "< #2" boolean (name < "Xyz Abc") equals TRUE;
-		UNIT_TEST.test "same_as #1" boolean (name.same_as "John Doe") equals TRUE;
-		UNIT_TEST.test "same_as #2" boolean (name.same_as "Jeff Doe") equals FALSE;
-		UNIT_TEST.test "same_as #3" boolean (name.same_as "john doe") equals TRUE;
-		UNIT_TEST.test "same_as #4" boolean (name.same_as "jeff doe") equals FALSE;
-		UNIT_TEST.test "== #1" boolean (name == "John Doe") equals TRUE;
-		UNIT_TEST.test "== #2" boolean (name == "john Doe") equals FALSE;
-		UNIT_TEST.test "== #3" boolean (name == "jeff Doe") equals FALSE;
-
-		UNIT_TEST.section "Modification";
-		UNIT_TEST.test "+ #1" string (name + " had a dog") equals "John Doe had a dog";
-		UNIT_TEST.test "+ #2" string (name + "") equals name;
-		UNIT_TEST.test "as_lower #1" string (name.as_lower) equals "john doe";
-		UNIT_TEST.test "as_lower #2" string (empty.as_lower) equals "";
-		UNIT_TEST.test "as_lower #3" string ("John 15".as_lower) equals "john 15";
-		UNIT_TEST.test "as_upper #1" string (name.as_upper) equals "JOHN DOE";
-		UNIT_TEST.test "as_upper #2" string (empty.as_upper) equals "";
-		UNIT_TEST.test "as_upper #3" string ("John 15".as_upper) equals "JOHN 15";
-
-		UNIT_TEST.section "Other features";
-		UNIT_TEST.test "first #1" character (name.first) equals 'J';
-		UNIT_TEST.test "first #2" character ("15th Street".first) equals '1';
-		UNIT_TEST.test "last #1" character (name.last) equals 'e';
-		UNIT_TEST.test "last #2" character ("15 + 15 = 30".last) equals '0';
-		UNIT_TEST.test "substring #1" string (name.substring 1 to 4) equals "John";
-		UNIT_TEST.test "substring #2" string (name.substring 6 to 8) equals "Doe";
-		UNIT_TEST.test "substring_index #1" integer (name.substring_index ("John", 1)) equals 1;
-		UNIT_TEST.test "substring_index #2" integer (name.substring_index ("Doe", 1)) equals 6;
-		UNIT_TEST.test "substring_index #3" integer (name.substring_index ("o", 1)) equals 2;
-		UNIT_TEST.test "substring_index #4" integer (name.substring_index ("o", 4)) equals 7;
-		UNIT_TEST.test "substring_index #5" integer (name.substring_index ("Smith", 1)) equals 0;
-		UNIT_TEST.test "first_substring_index #1" integer (name.first_substring_index "John") equals 1;
-		UNIT_TEST.test "first_substring_index #2" integer (name.first_substring_index "Doe") equals 6;
-		UNIT_TEST.test "first_substring_index #3" integer (name.first_substring_index "o") equals 2;
-		UNIT_TEST.test "first_substring_index #4" integer (name.first_substring_index "Smith") equals 0;
-
-		UNIT_TEST.section "Splitting a STRING";
-		values := name.split;
-		UNIT_TEST.test "split size" integer (values.count) equals 2;
-		UNIT_TEST.test "split val #1" string (values.item 1) equals "John";
-		UNIT_TEST.test "split val #2" string (values.item 2) equals "Doe";
-
-		name.split_in values;
-		UNIT_TEST.test "split_in size" integer (values.count) equals 4;
-		UNIT_TEST.test "split_in val #3" string (values.item 3) equals "John";
-		UNIT_TEST.test "split_in val #4" string (values.item 4) equals "Doe";
-		//TODO: This causes a compile error:
-		//UNIT_TEST.test "same_string #1" boolean (name.same_string "") equals FALSE;
-		//UNIT_TEST.test "same_string #2" boolean (name.same_string "John Doe") equals TRUE;
-		//UNIT_TEST.test "same_string #3" boolean (empty.same_string "Jim Doe") equals FALSE;
-		//UNIT_TEST.test "same_string #4" boolean (empty.same_string "") equals TRUE;
-		UNIT_TEST.test "to_string #1" string (name.to_string) equals name;
-		UNIT_TEST.test "to_string #2" string (empty.to_string) equals empty;
-	);
+  - run <-
+  (
+    + name:ABSTRACT_STRING;
+    + empty:ABSTRACT_STRING;
+    + values:ARRAY[STRING];
+
+    name := "John Doe";
+    empty := "";
+
+    UNIT_TEST.suite "ABSTRACT_STRING";
+
+    UNIT_TEST.section "basic";
+    UNIT_TEST.test "count #1" integer (name.count) equals 8;
+    UNIT_TEST.test "count #2" integer (empty.count) equals 0;
+    UNIT_TEST.test "lower #1" integer (name.lower) equals 1;
+    UNIT_TEST.test "lower #2" integer (empty.lower) equals 1;
+    UNIT_TEST.test "upper #1" integer (name.upper) equals 8;
+    UNIT_TEST.test "upper #2" integer (empty.upper) equals 0;
+
+    UNIT_TEST.section "Access";
+    UNIT_TEST.test "item #1" character (name.item 1) equals 'J';
+    UNIT_TEST.test "item #2" character (name.item 2) equals 'o';
+    UNIT_TEST.test "item #3" character (name.item 3) equals 'h';
+
+    UNIT_TEST.section "Testing";
+    UNIT_TEST.test "valid_index #1" boolean (name.valid_index 0) equals FALSE;
+    UNIT_TEST.test "valid_index #2" boolean (name.valid_index 1) equals TRUE;
+    UNIT_TEST.test "valid_index #3" boolean (name.valid_index 2) equals TRUE;
+    UNIT_TEST.test "valid_index #4" boolean (name.valid_index 3) equals TRUE;
+    UNIT_TEST.test "valid_index #5" boolean (name.valid_index 40) equals FALSE;
+    UNIT_TEST.test "valid_index #6" boolean (empty.valid_index 1) equals FALSE;
+    UNIT_TEST.test "valid_index #7" boolean (empty.valid_index 2) equals FALSE;
+    UNIT_TEST.test "is_empty #1" boolean (name.is_empty) equals FALSE;
+    UNIT_TEST.test "is_empty #2" boolean (empty.is_empty) equals TRUE;
+    UNIT_TEST.test "hash_code #1" integer (name.hash_code) equals 7915731; // TODO: is correct?
+    UNIT_TEST.test "hash_code #2" integer ("ABC".hash_code) equals 2022;   // TODO: is correct?
+    UNIT_TEST.test "has #1" boolean (name.has 'o') equals TRUE;
+    UNIT_TEST.test "has #2" boolean (name.has 'D') equals TRUE;
+    UNIT_TEST.test "has #3" boolean (name.has '8') equals FALSE;
+    UNIT_TEST.test "has #4" boolean (name.has 'x') equals FALSE;
+    UNIT_TEST.test "has #5" boolean (name.has 'd') equals FALSE;
+    UNIT_TEST.test "has_substring #1" boolean (name.has_substring "Doe") equals TRUE;
+    UNIT_TEST.test "has_substring #2" boolean (name.has_substring "John") equals TRUE;
+    UNIT_TEST.test "has_substring #3" boolean (name.has_substring "hn D") equals TRUE;
+    UNIT_TEST.test "has_substring #4" boolean (name.has_substring "e") equals TRUE;
+    UNIT_TEST.test "has_substring #5" boolean (name.has_substring "Jeff") equals FALSE;
+    UNIT_TEST.test "has_substring #6" boolean (name.has_substring "10") equals FALSE;
+    UNIT_TEST.test "occurrences #1" integer (name.occurrences  'o') equals 2;
+    UNIT_TEST.test "occurrences #2" integer (name.occurrences  'h') equals 1;
+    UNIT_TEST.test "occurrences #3" integer (name.occurrences  'X') equals 0;
+    UNIT_TEST.test "occurrences #4" integer (empty.occurrences  'X') equals 0;
+    UNIT_TEST.test "has_suffix #1" boolean (name.has_suffix "Doe") equals TRUE;
+    UNIT_TEST.test "has_suffix #2" boolean (name.has_suffix "oe") equals TRUE;
+    UNIT_TEST.test "has_suffix #3" boolean (name.has_suffix "e") equals TRUE;
+    UNIT_TEST.test "has_suffix #4" boolean (name.has_suffix "Smith") equals FALSE;
+    UNIT_TEST.test "has_suffix #5" boolean (name.has_suffix "o") equals FALSE;
+    UNIT_TEST.test "has_suffix #6" boolean (empty.has_suffix "Bye") equals FALSE;
+    UNIT_TEST.test "has_prefix #1" boolean (name.has_prefix "John") equals TRUE;
+    UNIT_TEST.test "has_prefix #2" boolean (name.has_prefix "Joh") equals TRUE;
+    UNIT_TEST.test "has_prefix #3" boolean (name.has_prefix "Jo") equals TRUE;
+    UNIT_TEST.test "has_prefix #4" boolean (name.has_prefix "J") equals TRUE;
+    UNIT_TEST.test "has_prefix #5" boolean (name.has_prefix "Jeff") equals FALSE;
+    UNIT_TEST.test "has_prefix #6" boolean (empty.has_prefix "Jack") equals FALSE;
+
+    UNIT_TEST.section "Testing/Conversion";
+    UNIT_TEST.test "is_boolean #1" boolean ("TRUE".is_boolean) equals TRUE;
+    UNIT_TEST.test "is_boolean #2" boolean ("FALSE".is_boolean) equals TRUE;
+    UNIT_TEST.test "is_boolean #3" boolean ("John".is_boolean) equals FALSE;
+    UNIT_TEST.test "is_boolean #4" boolean ("".is_boolean) equals FALSE;
+    UNIT_TEST.test "to_boolean #1" boolean ("TRUE".to_boolean) equals TRUE;
+    UNIT_TEST.test "to_boolean #2" boolean ("FALSE".to_boolean) equals FALSE;
+    UNIT_TEST.test "is_integer #1" boolean ("10".is_integer) equals TRUE;
+    UNIT_TEST.test "is_integer #2" boolean ("1029".is_integer) equals TRUE;
+    UNIT_TEST.test "is_integer #3" boolean ("-110".is_integer) equals TRUE;
+    UNIT_TEST.test "is_integer #4" boolean ("+110".is_integer) equals TRUE;
+    UNIT_TEST.test "is_integer #5" boolean ("Jack".is_integer) equals FALSE;
+    UNIT_TEST.test "is_integer #6" boolean ("".is_integer) equals FALSE;
+    UNIT_TEST.test "is_integer #7" boolean ("100.44".is_integer) equals FALSE;
+    UNIT_TEST.test "to_integer #1" integer ("100".to_integer) equals 100;
+    UNIT_TEST.test "to_integer #2" integer ("-12".to_integer) equals (-12);
+    UNIT_TEST.test "to_integer #3" integer ("0".to_integer) equals 0;
+    UNIT_TEST.test "is_hexadecimal #1" boolean ("16AF".is_hexadecimal) equals TRUE;
+    UNIT_TEST.test "is_hexadecimal #2" boolean ("10".is_hexadecimal) equals TRUE;
+    UNIT_TEST.test "is_hexadecimal #3" boolean ("16ZC".is_hexadecimal) equals FALSE;
+    UNIT_TEST.test "to_hexadecimal #1" integer ("16AF".to_hexadecimal) equals 5807;
+    UNIT_TEST.test "to_hexadecimal #2" integer ("10".to_hexadecimal) equals 16;
+    UNIT_TEST.test "is_octal #1" boolean ("5".is_octal) equals TRUE;
+    UNIT_TEST.test "is_octal #2" boolean ("25".is_octal) equals TRUE;
+    UNIT_TEST.test "is_octal #3" boolean ("2AF".is_octal) equals FALSE;
+    UNIT_TEST.test "is_octal #4" boolean ("Jack".is_octal) equals FALSE;
+    UNIT_TEST.test "to_octal #1" integer ("5".to_octal) equals 5;
+    UNIT_TEST.test "to_octal #2" integer ("25".to_octal) equals 21;
+    // TODO: Where is is_binary ?
+    UNIT_TEST.test "to_binary #1" integer ("101".to_binary) equals 5;
+    UNIT_TEST.test "to_binary #2" integer ("10000000101".to_binary) equals 1029;
+    UNIT_TEST.test "is_real_16_16 #1" boolean ("10".is_real_16_16) equals TRUE;
+    UNIT_TEST.test "is_real_16_16 #2" boolean ("-33.1".is_real_16_16) equals TRUE;
+    UNIT_TEST.test "is_real_16_16 #3" boolean ("13FD".is_real_16_16) equals FALSE;
+    UNIT_TEST.test "is_real_16_16 #4" boolean ("+100.39".is_real_16_16) equals TRUE;
+    UNIT_TEST.test "to_real_16_16 #1" real_16_16 ("10".to_real_16_16) equals 10.0;
+    UNIT_TEST.test "to_real_16_16 #2" real_16_16 ("-33.1".to_real_16_16) equals (-33.1);
+
+    UNIT_TEST.section "Indexing";
+    UNIT_TEST.test "item_code #1" integer (name.item_code 1) equals 74;
+    UNIT_TEST.test "item_code #2" integer (name.item_code 2) equals 111;
+    UNIT_TEST.test "item_code #3" integer (name.item_code 3) equals 104;
+    UNIT_TEST.test "index_of since #1" integer (name.index_of 'J' since 1) equals 1;
+    UNIT_TEST.test "index_of since #2" integer (name.index_of 'o' since 1) equals 2;
+    UNIT_TEST.test "index_of since #3" integer (name.index_of 'h' since 1) equals 3;
+    UNIT_TEST.test "index_of since #6" integer (name.index_of 'o' since 4) equals 7;
+    UNIT_TEST.test "index_of since #4" integer (name.index_of 'Z' since 1) equals 9;
+    UNIT_TEST.test "index_of since #5" integer (name.index_of 'J' since 2) equals 9;
+    UNIT_TEST.test "last_index_of since #1" integer (name.last_index_of 'o' since 8) equals 7;
+    UNIT_TEST.test "last_index_of since #2" integer (name.last_index_of 'o' since 5) equals 2;
+    UNIT_TEST.test "fast_index_of #1" integer (name.fast_index_of 'J') equals 1;
+    UNIT_TEST.test "fast_index_of #2" integer (name.fast_index_of 'o') equals 2;
+    UNIT_TEST.test "fast_index_of #3" integer (name.fast_index_of 'h') equals 3;
+    UNIT_TEST.test "fast_index_of #4" integer (name.fast_index_of 'D') equals 6;
+    UNIT_TEST.test "first_index_of #1" integer (name.first_index_of 'o') equals 2;
+    UNIT_TEST.test "first_index_of #2" integer (name.first_index_of 'n') equals 4;
+    UNIT_TEST.test "first_index_of #3" integer (name.first_index_of 'D') equals 6;
+    UNIT_TEST.test "fast_last_index_of #1" integer (name.fast_last_index_of 'e') equals 8;
+    UNIT_TEST.test "fast_last_index_of #2" integer (name.fast_last_index_of 'o') equals 7;
+    UNIT_TEST.test "fast_last_index_of #3" integer (name.fast_last_index_of 'n') equals 4;
+    UNIT_TEST.test "last_index_of #1" integer (name.last_index_of 'J') equals 1;
+    UNIT_TEST.test "last_index_of #2" integer (name.last_index_of 'o') equals 7;
+    UNIT_TEST.test "last_index_of #3" integer (name.last_index_of 'D') equals 6;
+    UNIT_TEST.test "index_of #1" integer (name.index_of 'J') equals 1;
+    UNIT_TEST.test "index_of #2" integer (name.index_of 'o') equals 2;
+    UNIT_TEST.test "index_of #3" integer (name.index_of 'h') equals 3;
+    UNIT_TEST.test "index_of #4" integer (name.index_of 'e') equals 8;
+
+    UNIT_TEST.section "Comparisons";
+    UNIT_TEST.test "equal #1" string "A" equals "A";
+    UNIT_TEST.test "equal #2" string name equals "John Doe";
+    UNIT_TEST.test "equal #3" string empty equals "";
+    UNIT_TEST.test "compare #1" integer (name.compare "Mike Smith") equals (-1);
+    UNIT_TEST.test "compare #2" integer (name.compare "Andy Jones") equals 1;
+    UNIT_TEST.test "compare #3" integer (name.compare "John Doe") equals 0;
+    UNIT_TEST.test "< #1" boolean (name < "ABC") equals FALSE;
+    UNIT_TEST.test "< #2" boolean (name < "Xyz Abc") equals TRUE;
+    UNIT_TEST.test "same_as #1" boolean (name.same_as "John Doe") equals TRUE;
+    UNIT_TEST.test "same_as #2" boolean (name.same_as "Jeff Doe") equals FALSE;
+    UNIT_TEST.test "same_as #3" boolean (name.same_as "john doe") equals TRUE;
+    UNIT_TEST.test "same_as #4" boolean (name.same_as "jeff doe") equals FALSE;
+    UNIT_TEST.test "== #1" boolean (name == "John Doe") equals TRUE;
+    UNIT_TEST.test "== #2" boolean (name == "john Doe") equals FALSE;
+    UNIT_TEST.test "== #3" boolean (name == "jeff Doe") equals FALSE;
+
+    UNIT_TEST.section "Modification";
+    UNIT_TEST.test "+ #1" string (name + " had a dog") equals "John Doe had a dog";
+    UNIT_TEST.test "+ #2" string (name + "") equals name;
+    UNIT_TEST.test "as_lower #1" string (name.as_lower) equals "john doe";
+    UNIT_TEST.test "as_lower #2" string (empty.as_lower) equals "";
+    UNIT_TEST.test "as_lower #3" string ("John 15".as_lower) equals "john 15";
+    UNIT_TEST.test "as_upper #1" string (name.as_upper) equals "JOHN DOE";
+    UNIT_TEST.test "as_upper #2" string (empty.as_upper) equals "";
+    UNIT_TEST.test "as_upper #3" string ("John 15".as_upper) equals "JOHN 15";
+
+    UNIT_TEST.section "Other features";
+    UNIT_TEST.test "first #1" character (name.first) equals 'J';
+    UNIT_TEST.test "first #2" character ("15th Street".first) equals '1';
+    UNIT_TEST.test "last #1" character (name.last) equals 'e';
+    UNIT_TEST.test "last #2" character ("15 + 15 = 30".last) equals '0';
+    UNIT_TEST.test "substring #1" string (name.substring 1 to 4) equals "John";
+    UNIT_TEST.test "substring #2" string (name.substring 6 to 8) equals "Doe";
+    UNIT_TEST.test "substring_index #1" integer (name.substring_index ("John", 1)) equals 1;
+    UNIT_TEST.test "substring_index #2" integer (name.substring_index ("Doe", 1)) equals 6;
+    UNIT_TEST.test "substring_index #3" integer (name.substring_index ("o", 1)) equals 2;
+    UNIT_TEST.test "substring_index #4" integer (name.substring_index ("o", 4)) equals 7;
+    UNIT_TEST.test "substring_index #5" integer (name.substring_index ("Smith", 1)) equals 0;
+    UNIT_TEST.test "first_substring_index #1" integer (name.first_substring_index "John") equals 1;
+    UNIT_TEST.test "first_substring_index #2" integer (name.first_substring_index "Doe") equals 6;
+    UNIT_TEST.test "first_substring_index #3" integer (name.first_substring_index "o") equals 2;
+    UNIT_TEST.test "first_substring_index #4" integer (name.first_substring_index "Smith") equals 0;
+
+    UNIT_TEST.section "Splitting a STRING";
+    values := name.split;
+    UNIT_TEST.test "split size" integer (values.count) equals 2;
+    UNIT_TEST.test "split val #1" string (values.item 1) equals "John";
+    UNIT_TEST.test "split val #2" string (values.item 2) equals "Doe";
+
+    name.split_in values;
+    UNIT_TEST.test "split_in size" integer (values.count) equals 4;
+    UNIT_TEST.test "split_in val #3" string (values.item 3) equals "John";
+    UNIT_TEST.test "split_in val #4" string (values.item 4) equals "Doe";
+    //TODO: This causes a compile error:
+    //UNIT_TEST.test "same_string #1" boolean (name.same_string "") equals FALSE;
+    //UNIT_TEST.test "same_string #2" boolean (name.same_string "John Doe") equals TRUE;
+    //UNIT_TEST.test "same_string #3" boolean (empty.same_string "Jim Doe") equals FALSE;
+    //UNIT_TEST.test "same_string #4" boolean (empty.same_string "") equals TRUE;
+    UNIT_TEST.test "to_string #1" string (name.to_string) equals name;
+    UNIT_TEST.test "to_string #2" string (empty.to_string) equals empty;
+  );
diff --git a/tests/lib_tests.li b/tests/lib_tests.li
index 6b20289..c481f3d 100644
--- a/tests/lib_tests.li
+++ b/tests/lib_tests.li
@@ -1,12 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+//                             Lisaac Library                                //
+//                                                                           //
+//                   LSIIT - ULP - CNRS - INRIA - FRANCE                     //
+//                                                                           //
+//   This program is free software: you can redistribute it and/or modify    //
+//   it under the terms of the GNU General Public License as published by    //
+//   the Free Software Foundation, either version 3 of the License, or       //
+//   (at your option) any later version.                                     //
+//                                                                           //
+//   This program is distributed in the hope that it will be useful,         //
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of          //
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
+//   GNU General Public License for more details.                            //
+//                                                                           //
+//   You should have received a copy of the GNU General Public License       //
+//   along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
+//                                                                           //
+//                     http://isaacproject.u-strasbg.fr/                     //
+///////////////////////////////////////////////////////////////////////////////
+
 Section Header
 
-	+ name := TEST;
+  + name := LIB_TESTS;
+
+  - copyright := "2009 Jeremy Cowgar";
+
+  - comment := "Unit testing of the Lisaac library.";
 
 Section Public
 
-	- main <-
-	(
+  - main <-
+  (
+    UNIT_TEST.init;
+
+    ABSTRACT_STRING_TEST.run;
 
-		ABSTRACT_STRING_TEST.run;
-		UNIT_TEST.test_results
-	);
+    UNIT_TEST.test_results
+  );

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list