Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Jun 02, 2010 8:58 pm
Zugg's List/DB Test script for v3.18 |
I know some people are interested in gory details, so I'm going to share the script I have been using to test the new string list and table code. As people report bugs, I add new test cases to this script to ensure that problems don't re-occur in a future version. If you have other test cases you'd like me to add, let me know.
Remember, this is just for testing the new string list and hashed tables. I have other scripts for testing other aspects of CMUD.
To use this script, copy it to a file (CMUDTESTDB.TXT) and then run CMUD and type:
#READ cmudtestdb.txt
Any errors will be displayed in red. Here is the script:
| Code: |
; CMUD testing script
; tests for new SuperObject tables, 2-Jun-10
;
; automatically tests parts of the CMUD scripting language
; run by typing:
; #READ cmudtestdb.txt
; successful lines are shown in green, errors in red
; a summary of errors is shown at the end
;
;----------------------
; ALIASES
;----------------------
; t category test-number literal test-value
; This alias checks to see if the literal string matches the test value
; If so, the line is output in green, otherwise in red.
; If there is an error, the error counter for the category is incremented
;
; Note the {%3} = {%4} syntax. Since %3 and %4 can evaluate to anything, including something with a space in it or a boolean operator, the {} delimits the result for the parser, while still expanding variables
; assume failure in case the parser is messed up
;
#ALIAS t {#ADD %1 1;#SHOW {%1 - %2 : %3 : %4 :};#IF ({%3} = {%4}) {#COLOR green;#ADD %1 -1} {#COLOR high,red}}
;
#ALIAS TrueRes {#SHOW {%1 - %2};#COLOR green}
#ALIAS FalseRes {#SHOW {%1 - %2};#COLOR high,red;#ADD %1 1}
;
; TestLine Category Literal
; - tests to see if the last line output is correct
; - assume failure in case parser is messed up
#ALIAS TestLine {#ADD %1 1;#IF ({%line} = {%-2}) {#COLOR green;#ADD %1 -1} {#COLOR high,red}}
;
; This is the test function for Triggers:
; tt result literal
#ALIAS tt {#SHOW %2;#IF ({@OK} = {%1}) {#color green} {#ADD Trigger 1;#COLOR high,red};#VAR OK 0}
;
; START TIMER
#VAR StartTime %secs
;
; ***** BEGIN TESTS HERE *****
;-----------------------------
Array = 0
Table = 0
Assign = 0
;
; basic list assignment
list=""
list={a|b|c}
t Array 1 "[""a"",""b"",""c""]" %json(list)
; overwrite one list with another
list={d|e|f}
t Array 2 "[""d"",""e"",""f""]" %json(list)
t Array 3 "d|e|f" @list
t Array 4 "d" @list.1
t Array 5 "e" %db(@list,2)
t Array 6 "f" %item(@list,3)
; various null equality tests
list=%null
t Array 7 "1" %null(@list)
#VAR list ""
t Array 8 "1" %null(@list)
#VAR list %null
t Array 9 "1" %null(@list)
#unvar list
t Array 10 "1" %null(@list)
; test a literal string assignment...shouldn't make a json table
list="a|b|c"
t Array 11 "list" %json(list)
t Array 12 "a|b|c" @list
t Array 13 "b" @list.2
list={a|b|c}
t Array 14 "0" %eval(@list=%null)
t Array 15 "0" %eval(%null=@list)
; add a nested list to the list
#ADDITEM list {1|2|3}
t Array 16 "[""a"",""b"",""c"",[1,2,3]]" %json(list)
t Array 17 3 %numitems(@list.4)
t Array 18 3 %numitems(%item(@list,4))
t Array 19 2 %item(@list.4,2)
;
; Tables
;
; basic table assignment
db=""
db={name=zugg|race=dwarf}
t Table 1 "{""race"":""dwarf"",""name"":""zugg""}" %json(db)
t Table 2 "race=dwarf|name=zugg" @db
t Table 3 "dwarf" @db.race
t Table 4 "zugg" %db(@db,name)
t Table 5 "" @db.test
#addkey db level 20
t Table 6 20 @db.level
; add a nested array to table
#addkey db arr {1|2|3}
t Table 7 "[1,2,3]" %json(@db.arr)
db=""
#addkey db key1 {1|2|3|4}
t Table 10 "{""key1"":[1,2,3,4]}" %json(db)
t Table 11 4 %numitems(@db.key1)
t Table 12 4 %numitems(%db(@db,key1))
t Table 13 2 %item(@db.key1,2)
t Table 14 "1|2|3|4" @db.key1
#addkey db key2 "1|2|3|4"
t Table 15 "{""key2"":""1|2|3|4"",""key1"":[1,2,3,4]}" %json(db)
;
; Assignment
;
list=""
; basic assignment
list.1 = 1
list.3 = 3
t Assign 1 "[1,null,3]" %json(list)
t Assign 2 "1||3" @list
t Assign 3 1 @list.1
t Assign 4 "" @list.2
; assign a nested list
list.2 = {a|b|c}
t Assign 5 "[1,[""a"",""b"",""c""],3]" %json(list)
; nested assignment
list.2.4 = "d"
list.2.1 = "aa"
t Assign 5 "[1,[""aa"",""b"",""c"",""d""],3]" %json(list)
list = ""
list.1.2.3 = "abc"
t Assign 6 "[[null,[null,null,""abc""]]]" %json(list)
list.1.1 = "a|b|c"
t Assign 7 "[[""a|b|c"",[null,null,""abc""]]]" %json(list)
db=""
db.name = zugg
db.level = 20
db.RACE = dwarf
t Assign 8 "{""level"":20,""RACE"":""dwarf"",""name"":""zugg""}" %json(db)
; test case insensitivity
t Assign 9 dwarf @db.race
t Assign 10 dwarf @db.RACE
db.level.1 = 123
db.level.2 = 999
t Assign 11 "{""level"":[123,999],""RACE"":""dwarf"",""name"":""zugg""}" %json(db)
db.level.3.Key = value
t Assign 12 "{""level"":[123,999,{""Key"":""value""}],""RACE"":""dwarf"",""name"":""zugg""}" %json(db)
t Assign 13 value @db.level.3.key
list={a|b|c}
list.name = zugg
; converting a list to a keyed table
t Assign 14 "{""3"":""c"",""2"":""b"",""1"":""a"",""name"":""zugg""}" %json(list)
t Assign 15 a @list.1
t Assign 16 zugg @list.name
; using nested var name to commands like #ADD and #ADDITEM
#VAR db ""
#ADDKEY db Key 1
#ADD db.Key 1
t Assign 17 "2" @db.Key
#VAR db ""
#ADDKEY db Key 1
#ADDITEM db.Key 2
t Assign 18 "1|2" @db.Key
; create a new nested table on the fly
#ADDKEY db.char name zugg
t Assign 19 "{""Key"":[1,2],""char"":{""name"":""zugg""}}" %json(db)
t Assign 20 zugg @db.char.name
t Assign 21 2 @db.Key.2
#VAR EndTime %secs
#show "Time: " (@EndTime-@StartTime) ms
;----------------
; output summary of results
#ALIAS show {#SHOW @{%1} errors in category %1}
#cr;#show "------Results------"
show Array
show Table
show Assign |
|
|