-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhmm-test.lua
More file actions
86 lines (77 loc) · 3.65 KB
/
hmm-test.lua
File metadata and controls
86 lines (77 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local lu = require('luaunit')
local hmm = require('hmmlua')
local json=require('json')
function TestDLL()
local closed=json.decode(hmm.close("",0))
lu.assertEquals(closed,false)
local created=json.decode(hmm.create("",0))
lu.assertEquals(created,true)
end
function TestVersion()
hmm.close("",0)
hmm.create("",0)
local result=json.decode(hmm.version("",0))
lu.assertEquals(result,1006)
end
function TestInfo()
hmm.close("",0)
local created=json.decode(hmm.create("",0))
lu.assertEquals(created,true)
local result=json.decode(hmm.info("",0))
lu.assertEquals(result.Name,"")
lu.assertEquals(result.Desc,"")
end
-- function TestEscape()
-- local cc = hmm.ControlCode:New();
-- cc:WithCommand(hmm.Command:New("\\", "0", "\\\\"));
-- cc:WithCommand(hmm.Command:New("\n", "1", "\\n"));
-- cc:WithCommand(hmm.Command:New("", "2", "\\"));
-- --转义保留符号
-- lu.assertEquals("This is a test \x02 string.", cc:Escape("This is a test \x02 string."));
-- lu.assertEquals("This is a test \x02 string.", cc:Unescape("This is a test \x02 string."));
-- lu.assertEquals("This is a test \x03 string.", cc:Escape("This is a test \x03 string."));
-- lu.assertEquals("This is a test \x03 string.", cc:Unescape("This is a test \x03 string."));
-- lu.assertEquals("This is a test \x04 string.", cc:Escape("This is a test \x04 string."));
-- lu.assertEquals("This is a test \x04 string.", cc:Unescape("This is a test \x04 string."));
-- --转义斜杠
-- lu.assertEquals("This is a test \\\\ string.", cc:Escape("This is a test \\ string."));
-- lu.assertEquals("This is a test \\ string.", cc:Unescape("This is a test \\\\ string."));
-- --测试转义
-- lu.assertEquals("This is a test \\n string.", cc:Escape("This is a test \n string."));
-- --测试解转义
-- lu.assertEquals("This is a test \n string.", cc:Unescape("This is a test \\n string."));
-- --测试一致性
-- lu.assertEquals("This is a test \\ string.", cc:Unescape(cc:Escape("This is a test \\ string.")));
-- --测试独立的斜杠转解意会被去除
-- lu.assertEquals("This is a test string.", cc:Unescape("This is a test \\ string."));
-- end
-- function TestInternal()
-- local cc = hmm.ControlCode:New()
-- :WithCommand(hmm.Command:New("\x02", "a", "\\2"))
-- :WithCommand(hmm.Command:New("\x03", "b", "\\3"))
-- :WithCommand(hmm.Command:New("\x04", "c", "\\4"))
-- ;
-- lu.assertEquals("\x02", cc:Unescape("\\2"));
-- lu.assertEquals("\x03", cc:Unescape("\\3"));
-- lu.assertEquals("\x04", cc:Unescape("\\4"));
-- lu.assertEquals("\\2", cc:Escape("\x02"));
-- lu.assertEquals("\\3", cc:Escape("\x03"));
-- lu.assertEquals("\\4", cc:Escape("\x04"));
-- lu.assertEquals("\x04\x02", cc:Unescape("\\4\\2"));
-- lu.assertEquals("\\4\\2", cc:Escape("\x04\x02"));
-- lu.assertEquals("\x04\x03", cc:Unescape("\\4\\3"));
-- lu.assertEquals("\\4\\3", cc:Escape("\x04\x03"));
-- lu.assertEquals("\x04\x04", cc:Unescape("\\4\\4"));
-- lu.assertEquals("\\4\\4", cc:Escape("\x04\x04"));
-- end
-- function TestMulti()
-- local cc = hmm.ControlCode:New()
-- :WithCommand(hmm.Command:New("\\", "0", "\\\\"))
-- :WithCommand(hmm.Command:New("\n", "1", "\\n"))
-- :WithCommand(hmm.Command:New("%", "2", "\\%"))
-- :WithCommand(hmm.Command:New("$", "3", "\\$"))
-- :WithCommand(hmm.Command:New("", "4", "\\"))
-- lu.assertEquals("a\n%$b\\n\\%\\$$0$1\\$0\\$1", cc:Unescape("a\\n\\%\\$b\\\\n\\\\%\\\\$\\$0\\$1\\\\$0\\\\$1"));
-- lu.assertEquals("\\n", cc:Unescape("\\\\n"));
-- end
-- os.exit(lu.LuaUnit.run())