Skip to content
Browse files

tests: adds null array roundtrip issue per gh-4

  • Loading branch information...
1 parent c3255bc commit eba5ca982bc21227c9e97fd1c266dd53b126aa9a @harningt committed Dec 29, 2011
Showing with 61 additions and 0 deletions.
  1. +61 −0 tests/lunit-simple-decode.lua
View
61 tests/lunit-simple-decode.lua
@@ -19,6 +19,18 @@ function test_decode_default_null()
assert_equal(json.util.null, json.decode('null'))
end
+function test_decode_array_simple_with_only_null()
+ local result = assert(json.decode('[null]', json.decode.simple))
+ assert_nil(result[1])
+ assert_equal(1, result.n)
+end
+
+function test_decode_array_default_with_only_null()
+ local result = assert(json.decode('[null]'))
+ assert_equal(json.util.null, result[1])
+ assert_equal(1, #result)
+end
+
function test_decode_array_simple_with_null()
local result = assert(json.decode('[1, null, 3]', json.decode.simple))
assert_equal(1, result[1])
@@ -35,6 +47,55 @@ function test_decode_array_default_with_null()
assert_equal(3, #result)
end
+function test_decode_small_array_simple_with_trailing_null()
+ local result = assert(json.decode('[1, null]', json.decode.simple))
+ assert_equal(1, result[1])
+ assert_nil(result[2])
+ assert_equal(2, result.n)
+end
+
+function test_decode_small_array_default_with_trailing_null()
+ local result = assert(json.decode('[1, null]'))
+ assert_equal(1, result[1])
+ assert_equal(json.util.null, result[2])
+ assert_equal(2, #result)
+end
+
+
+function test_decode_small_array_simple_with_trailing_null()
+ local result = assert(json.decode('[1, null]', json.decode.simple))
+ assert_equal(1, result[1])
+ assert_nil(result[2])
+ assert_equal(2, result.n)
+end
+
+function test_decode_small_array_default_with_trailing_null()
+ local result = assert(json.decode('[1, null]'))
+ assert_equal(1, result[1])
+ assert_equal(json.util.null, result[2])
+ assert_equal(2, #result)
+end
+
+
+function test_decode_array_simple_with_trailing_null()
+ local result = assert(json.decode('[1, null, 3, null]', json.decode.simple))
+ assert_equal(1, result[1])
+ assert_nil(result[2])
+ assert_equal(3, result[3])
+ assert_nil(result[4])
+ assert_equal(4, result.n)
+end
+
+function test_decode_array_default_with_trailing_null()
+ local result = assert(json.decode('[1, null, 3, null]'))
+ assert_equal(1, result[1])
+ assert_equal(json.util.null, result[2])
+ assert_equal(3, result[3])
+ assert_equal(json.util.null, result[4])
+ assert_equal(4, #result)
+end
+
+
function test_decode_object_simple_with_null()
local result = assert(json.decode('{x: null}', json.decode.simple))
assert_nil(result.x)

0 comments on commit eba5ca9

Please sign in to comment.
Something went wrong with that request. Please try again.