Skip to content

Commit

Permalink
更新测试集
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Oct 24, 2022
1 parent 842b043 commit 91bb6c8
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 45 deletions.
6 changes: 3 additions & 3 deletions test/basic.lk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import "test/module"
import 'test/gf'

shy func = fn (...) {
func := fn (...) {
// `#`获取长度,`...`为变长参数,`{}`构造Table
// `#{...}`即获取变长参数的长度(有多少个参数)
print(fmt('[args: %d]\t', #{...}), ...)
Expand All @@ -20,7 +20,7 @@ func(test2.const)

// "`" 包裹的str,为原始字符串,不会被转义
// 如果第一个字符为换行符`\n`,则第一个`\n`会被忽略
shy long = `
long := `
abc`

if #long >= 0 and '' {
Expand All @@ -47,6 +47,6 @@ func(_VERSION, math.pi)
// 与js类似,大部分类型都可转为json str
func(str(test2))

shy gf = new(Girlfriend)
gf := new(Girlfriend)
gf:herName('lxy')
gf:hello()
12 changes: 4 additions & 8 deletions test/bench.lk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
shy path = 'test/module'
path := 'test/module'

shy fn bench(func) {
bench := fn(func) {
shy t1 = os.time()
for i = 0, 10000 {
func()
Expand All @@ -9,12 +9,8 @@ shy fn bench(func) {
rt t2 - t1
}

shy t1 = bench(fn() {
dofile(path + '.lk')
})
t1 := bench(fn() => dofile(path + '.lk'))

shy t2 = bench(fn() {
dofile(path + '.lkc')
})
t2 := bench(fn() => dofile(path + '.lkc'))

print(fmt("Using %s.lk(c)\nSource: %d ms, Compiled: %d ms, %d times", path, t1, t2, t1 / t2))
12 changes: 6 additions & 6 deletions test/error.lk
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
shy fn div0(a, b) {
div0 := fn(a, b) {
if b == 0 {
error("DIV BY ZERO !")
} else {
rt a / b
}
}

shy fn div1(a, b) {rt div0(a, b)}
shy fn div2(a, b) {rt div1(a, b)}
div1 := fn(a, b) => div0(a, b)
div2 := fn(a, b) => div1(a, b)

shy ok, result = pcall(div2, 4, 2); print(ok, result)
shy ok, err = pcall(div2, 5, 0); print(ok, err)
shy ok, err = pcall(div2, {}, {}); print(ok, err)
ok, result := pcall(div2, 4, 2); print(ok, result)
ok, err := pcall(div2, 5, 0); print(ok, err)
ok, err := pcall(div2, {}, {}); print(ok, err)
1 change: 0 additions & 1 deletion test/gf.lk
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ fn Girlfriend:herName(name) {
fn Girlfriend:hello() {
print(fmt('My honey %s ~', self.name))
}

4 changes: 1 addition & 3 deletions test/http_listen.lk
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'test/http_header'

shy fn handle(req) {
rt 200, fmt('%s %s\n\n%s\n%s', req.method, req.url, Header:fromTable(req.headers), req.body)
}
handle := fn(req) => 200, fmt('%s %s\n\n%s\n%s', req.method, req.url, Header:fromTable(req.headers), req.body)

if http.listen(':8080', handle) != nil {
error(err)
Expand Down
7 changes: 3 additions & 4 deletions test/http_req.lk
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import 'test/http_header'

shy resp, err = http.post(
resp, err := http.post(
'http://httpbin.org/post',
{'accept': 'application/json'},
'{"foo": "bar"}'
)

if err == nil {
shy h = Header:fromTable(resp.headers)
print(h)
print(Header:fromTable(resp.headers))
}

shy resp, _ = http.req(
resp, _ := http.req(
'delete',
'http://httpbin.org/delete',
{'accept': 'application/json'},
Expand Down
6 changes: 3 additions & 3 deletions test/metatable.lk
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fn Vector:__str() {
rt 'Vector(' + str(self.x) + ', ' + str(self.y) + ')'
}

shy v1 = new(Vector)
shy v2 = Vector.new(3, 4)
v1 := new(Vector)
v2 := Vector.new(3, 4)
v1:set(1, 2)
shy v3 = v1 + v2
v3 := v1 + v2
print(v3.x, v3.y)
print(fmt('%s + %s = %s', v1, v2, v3))
2 changes: 1 addition & 1 deletion test/module.lk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shy a = 1
a := 1
class test2 {
'b': 2
}
Expand Down
2 changes: 1 addition & 1 deletion test/module.lkc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"v":"0.1.4","si":"LANG_LK","h":"","p":{"s":"test/module.lk","ld":0,"lld":0,"np":0,"iv":1,"ms":5,"c":[1,16459,32897,49345,16826442,2155888648,4210758,65665,65729,16826442,107,4210822,82113,16683,25231498,8388645],"cs":[1,"test2","b",2,"const","add"],"us":[{"is":1,"idx":0}],"ps":[{"s":"test/module.lk","ld":8,"lld":10,"np":1,"iv":0,"ms":3,"c":[133,16777293,73,8388645],"cs":[],"us":[{"is":1,"idx":0}],"ps":[],"li":[9,9,9,10],"lvs":[{"vn":"n","spc":0,"epc":4}],"uns":["a"]},{"s":"test/module.lk","ld":12,"lld":15,"np":1,"iv":0,"ms":6,"c":[69,4194439,16793699,64,129,4194567,8388933,33636557,16826442,8388645],"cs":["b"],"us":[{"is":1,"idx":1},{"is":1,"idx":0}],"ps":[],"li":[13,13,13,14,14,14,14,14,14,15],"lvs":[{"vn":"self","spc":0,"epc":10}],"uns":["add","a"]}],"li":[1,2,3,3,3,2,6,6,6,6,10,12,12,15,12,15],"lvs":[{"vn":"a","spc":1,"epc":16},{"vn":"add","spc":11,"epc":16}],"uns":["_ENV"]}}
{"v":"0.1.5","si":"LANG_LK","h":"","p":{"s":"test/module.lk","ld":0,"lld":0,"np":0,"iv":1,"ms":5,"c":[1,16459,32897,49345,16826442,2155888648,4210758,65665,65729,16826442,107,4210822,82113,16683,25231498,8388645],"cs":[1,"test2","b",2,"const","add"],"us":[{"is":1,"idx":0}],"ps":[{"s":"test/module.lk","ld":8,"lld":10,"np":1,"iv":0,"ms":3,"c":[133,16777293,73,8388645],"cs":[],"us":[{"is":1,"idx":0}],"ps":[],"li":[9,9,9,10],"lvs":[{"vn":"n","spc":0,"epc":4}],"uns":["a"]},{"s":"test/module.lk","ld":12,"lld":15,"np":1,"iv":0,"ms":6,"c":[69,4194439,16793699,64,129,4194567,8388933,33636557,16826442,8388645],"cs":["b"],"us":[{"is":1,"idx":1},{"is":1,"idx":0}],"ps":[],"li":[13,13,13,14,14,14,14,14,14,15],"lvs":[{"vn":"self","spc":0,"epc":10}],"uns":["add","a"]}],"li":[1,2,3,3,3,2,6,6,6,6,10,12,12,15,12,15],"lvs":[{"vn":"a","spc":1,"epc":16},{"vn":"add","spc":11,"epc":16}],"uns":["_ENV"]}}
16 changes: 8 additions & 8 deletions test/os.lk
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ shy fn pri(section, ...) {
print('### ' + section + ' ###')
print(...)
}
shy tmpDir = os.tmp()
tmpDir := os.tmp()
pri('temp_dir: ', tmpDir)

shy path = tmpDir + '/test'
shy err = os.write(path, "test")
path := tmpDir + '/test'
err := os.write(path, "test")
pri('write err: ', err)
shy data, err = os.read(path)
data, err := os.read(path)
pri('write content: ', data, err)

shy err = os.rm(path, false)
err := os.rm(path, false)
pri('rm err: ', err)

shy result, ok = os.exec('ls', '-l', 'test')
result, ok := os.exec('ls', '-l', 'test')
pri('ls result: ', ok, result)

pri('env HOME: ', os.env('HOME'))
pri('date: ', os.date())

shy dirs, err = os.ls('test')
dirs, err := os.ls('test')
for _, dir in dirs {
print(dir)
}

shy err = os.mkdir('test', true)
err := os.mkdir('test', true)
pri('mkdir err: ', err)

pri('os.sleep(1)', os.sleep(1))
Expand Down
6 changes: 3 additions & 3 deletions test/re.lk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
shy pattern = `([A-Za-z0-9]+).*(\*).*(\[\])`
shy text = 'foo9 * []'
shy matches = re.find(pattern, text)
pattern := `([A-Za-z0-9]+).*(\*).*(\[\])`
text := 'foo9 * []'
matches := re.find(pattern, text)
for k, v in matches {
print(k, v)
}
4 changes: 2 additions & 2 deletions test/sync.lk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
fn foo(a) {
shy fn foo(a) {
print("foo 函数输出", a)
rt sync.yield(2 * a) // 返回 2*a 的值
}

co = sync.create(fn (a , b) {
co := sync.create(fn (a , b) {
print("第一次协同程序执行输出", a, b) // co-body 1 10
shy r = foo(a + 1)

Expand Down
4 changes: 2 additions & 2 deletions test/table.lk
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
shy pri = fn (tb) {
pri := fn (tb) {
for key, value in tb {
print(key, value, type(value))
}
print()
}

shy tb = {5, 'd': str(4), 'c': false}
tb := {5, 'd': str(4), 'c': false}
pri(tb)

// 赋值
Expand Down

0 comments on commit 91bb6c8

Please sign in to comment.