From 1334c0ae67fdf4cb1377e0e7a3ef291f5cf694c0 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sat, 19 Oct 2024 00:35:11 +0800 Subject: Fixed issue #174. --- spec/inputs/loops.yue | 17 +++++++++++++ spec/outputs/5.1/loops.lua | 49 ++++++++++++++++++++++++++++++++++++++ spec/outputs/codes_from_doc.lua | 16 +++++++++++++ spec/outputs/codes_from_doc_zh.lua | 16 +++++++++++++ spec/outputs/loops.lua | 37 ++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+) (limited to 'spec') diff --git a/spec/inputs/loops.yue b/spec/inputs/loops.yue index 5cadbf0..c5b28b3 100644 --- a/spec/inputs/loops.yue +++ b/spec/inputs/loops.yue @@ -196,3 +196,20 @@ do print i continue print "abc" + +do + while byte := stream::read_one! + -- do something with the byte + continue if byte == 0 + print byte + +do + local func + while success, result := try func 1, 2, 3 + catch err + print err + print result + +do + until x := func 'a', b do + print "false expected" diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua index cc019e0..57b19be 100644 --- a/spec/outputs/5.1/loops.lua +++ b/spec/outputs/5.1/loops.lua @@ -440,3 +440,52 @@ do end end end +do + repeat + local _cond_0 = false + local _continue_0 = false + repeat + local byte = stream:read_one() + if byte then + if byte == 0 then + _cond_0 = false + _continue_0 = true + break + end + print(byte) + else + break + end + _cond_0 = false + _continue_0 = true + until true + if not _continue_0 then + break + end + until _cond_0 +end +do + local func + repeat + local success, result = xpcall(function() + return func(1, 2, 3) + end, function(err) + return print(err) + end) + if success then + print(result) + else + break + end + until false +end +do + repeat + x = func('a', b) + if not x then + print("false expected") + else + break + end + until false +end diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 4073056..e2bba8e 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua @@ -585,6 +585,14 @@ do end end print("OK") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false local list = { 1, 2, @@ -2583,6 +2591,14 @@ do end end print("OK") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false local list = { 1, 2, diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index f251450..4839525 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua @@ -585,6 +585,14 @@ do end end print("好的") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false local list = { 1, 2, @@ -2577,6 +2585,14 @@ do end end print("好的") +repeat + local byte = stream:read_one() + if byte then + print(byte) + else + break + end +until false local list = { 1, 2, diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua index 40e27b9..8624d49 100644 --- a/spec/outputs/loops.lua +++ b/spec/outputs/loops.lua @@ -333,3 +333,40 @@ do ::_continue_11:: end end +do + repeat + local byte = stream:read_one() + if byte then + if byte == 0 then + goto _continue_13 + end + print(byte) + else + break + end + ::_continue_13:: + until false +end +do + local func + repeat + local success, result = xpcall(func, function(err) + return print(err) + end, 1, 2, 3) + if success then + print(result) + else + break + end + until false +end +do + repeat + x = func('a', b) + if not x then + print("false expected") + else + break + end + until false +end -- cgit v1.2.3-55-g6feb