mirror of https://github.com/arendst/Tasmota.git
Update Berry tests from upstream (#18472)
This commit is contained in:
parent
01ba3d28cd
commit
f46b9f4e2d
|
@ -248,3 +248,12 @@ assert(bytes("0011223344").reverse(1, nil) == bytes("0044332211"))
|
|||
|
||||
assert(bytes("0011223344").reverse(nil, nil, 2) == bytes("2233001144"))
|
||||
assert(bytes("001122334455").reverse(nil, nil, 3) == bytes("334455001122"))
|
||||
|
||||
# tobool returns `true` is bytes() is not null, `false` if empty
|
||||
assert(bool(bytes()) == false)
|
||||
assert(bytes().tobool() == false)
|
||||
assert(!bytes())
|
||||
|
||||
assert(bool(bytes("00")) == true)
|
||||
assert(bytes("01").tobool() == true)
|
||||
assert(bytes("02"))
|
||||
|
|
|
@ -120,3 +120,24 @@ assert(A.a == 1)
|
|||
assert(B.a == A)
|
||||
assert(B.b == 1)
|
||||
assert(B.c == A)
|
||||
|
||||
#- static class get an implicit `_class` variable -#
|
||||
class A
|
||||
static def f(x) return _class end
|
||||
end
|
||||
assert(A.f() == A)
|
||||
|
||||
#- static class within a class -#
|
||||
class A
|
||||
static class B
|
||||
static def f() return 1 end
|
||||
def g() return 2 end
|
||||
end
|
||||
end
|
||||
a = A()
|
||||
b = A.B()
|
||||
assert(classname(a) == 'A')
|
||||
assert(classname(b) == 'B')
|
||||
assert(A.B.f() == 1)
|
||||
assert(b.g() == 2)
|
||||
assert(super(B) == nil)
|
||||
|
|
|
@ -31,3 +31,14 @@ assert(a.a == 3)
|
|||
import introspect
|
||||
m = introspect.module("math") # load module `math`, assign to `m` and don't create a global variable
|
||||
assert(type(m.pi) == 'real')
|
||||
|
||||
#- name -#
|
||||
import string
|
||||
assert(introspect.name(string) == 'string')
|
||||
assert(introspect.name(print) == nil) # native C function don't have a registered name
|
||||
assert(introspect.name("foo") == nil)
|
||||
class A def a() end static def b() end static var c end
|
||||
assert(introspect.name(A) == 'A')
|
||||
assert(introspect.name(A.a) == 'a')
|
||||
assert(introspect.name(A.b) == 'b')
|
||||
assert(introspect.name(A.c) == nil)
|
||||
|
|
|
@ -80,3 +80,16 @@ class map2 : map def init() super(self).init() end end
|
|||
var m = map2()
|
||||
m['key'] = 1
|
||||
assert_dump(m, '{"key":1}')
|
||||
|
||||
# sweep dumping nested arrays of diffrent sizes
|
||||
# this tests for any unexpanded stack conditions
|
||||
for count : 10..200
|
||||
var arr = [[]]
|
||||
var last_arr = arr
|
||||
for i : 0..count
|
||||
var pushed = [i]
|
||||
last_arr.push(pushed)
|
||||
last_arr = pushed
|
||||
end
|
||||
json.dump(arr)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
|
||||
|
||||
def assert_load_failed(text)
|
||||
assert(json.load(text) == nil)
|
||||
end
|
||||
|
||||
var input_file = open("tests/json_test_cases.json", "r")
|
||||
var test_cases = json.load(input_file.read())
|
||||
|
||||
# check positive cases
|
||||
var has_failed_positives = false
|
||||
for case_name : test_cases["positive"].keys()
|
||||
var case = test_cases["positive"][case_name]
|
||||
var val = json.load(case)
|
||||
if val == nil && case != "null"
|
||||
print("Failed to load case: " + case_name)
|
||||
has_failed_positives = true
|
||||
end
|
||||
end
|
||||
|
||||
if has_failed_positives
|
||||
assert(false)
|
||||
end
|
||||
|
||||
# check negative cases
|
||||
|
||||
var has_failed_negatives = false
|
||||
for case_name : test_cases["negative"].keys()
|
||||
var case = test_cases["negative"][case_name]
|
||||
|
||||
var val = json.load(case)
|
||||
if val != nil
|
||||
print("Failed to fail case: " + case_name + ", got: " + json.dump(val))
|
||||
has_failed_negatives = true
|
||||
end
|
||||
end
|
||||
|
||||
if has_failed_negatives
|
||||
# assert(false)
|
||||
end
|
||||
|
||||
# check "any" cases, only for crashes
|
||||
|
||||
for case_name : test_cases["any"].keys()
|
||||
var case = test_cases["any"][case_name]
|
||||
var val = json.load(case)
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import json
|
||||
|
||||
# this test must be in a separate file, so that the stack is not expanded yet by other tests
|
||||
|
||||
arr = "{"
|
||||
for i : 0..1000
|
||||
arr += '"k' + str(i) + '": "v' + str(i) + '",'
|
||||
end
|
||||
arr += "}"
|
||||
|
||||
json.load(arr)
|
|
@ -30,3 +30,10 @@ m.remove(2)
|
|||
assert(str(m) == '{1: 2}')
|
||||
m.remove(1)
|
||||
assert(str(m) == '{}')
|
||||
|
||||
# allow booleans to be used as keys
|
||||
m={true:10, false:20}
|
||||
assert(m.contains(true))
|
||||
assert(m.contains(false))
|
||||
assert(m[true] == 10)
|
||||
assert(m[false] == 20)
|
||||
|
|
Loading…
Reference in New Issue