summary refs log tree commit diff stats
path: root/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/test.lua b/test.lua
index 077f139..5a1bd4d 100644
--- a/test.lua
+++ b/test.lua
@@ -405,6 +405,53 @@ do -- long comments
     end
 end -- long comments
 
+do -- numbers
+    local luatokens = require "luatokens"
+    local tokens = luatokens.defs
+    local state, err, etoken, estate = parser.parse(tokens, [[
+     3   345   0xff   0xBEBADA
+     3.0     3.1416     314.16e-2     0.31416E1     34e1
+     0x0.1E  0xA23p-4   0X1.921FB54442D18P+1]])
+    local case = case()
+    if not state then
+        print(case, "---- IN  TOKENS ----")
+        print(case, err, etoken)
+        for i,v in pairs(estate) do
+            print(case, i, v)
+        end
+        print(case, "---- OUT TOKENS ----")
+    else
+        -- integers
+        assert(table.remove(state, 1) == luatokens.tokens.TK_INT)
+        assert(table.remove(state, 1) == 3)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_INT)
+        assert(table.remove(state, 1) == 345)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_INT)
+        assert(table.remove(state, 1) == 0xff)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_INT)
+        assert(table.remove(state, 1) == 0xBEBADA)
+        -- floats
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 3.0)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 3.1416)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 314.16e-2)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 0.31416E1)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 34e1)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 0x0.1E)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 0xA23p-4)
+        assert(table.remove(state, 1) == luatokens.tokens.TK_FLT)
+        assert(table.remove(state, 1) == 0x1.921FB54442D18P+1)
+        assert(table.remove(state, 1) == nil)
+        assert(state.line == 3)
+    end
+end -- numbers
+
 do -- FUCK
     local luatokens = require "luatokens"
     local luatokens_file = io.open("./luatokens.lua", "r")