From 02060b7a37d88d4e92cf64a008c0651eae432c12 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 23 Aug 2022 16:08:53 -0300 Subject: Simpler handling of Byte Order Mark (BOM) --- testes/main.lua | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'testes') diff --git a/testes/main.lua b/testes/main.lua index 9def6386..9187420e 100644 --- a/testes/main.lua +++ b/testes/main.lua @@ -94,6 +94,33 @@ RUN('echo "print(10)\nprint(2)\n" | lua > %s', out) checkout("10\n2\n") +-- testing BOM +prepfile("\xEF\xBB\xBF") +RUN('lua %s > %s', prog, out) +checkout("") + +prepfile("\xEF\xBB\xBFprint(3)") +RUN('lua %s > %s', prog, out) +checkout("3\n") + +prepfile("\xEF\xBB\xBF# comment!!\nprint(3)") +RUN('lua %s > %s', prog, out) +checkout("3\n") + +-- bad BOMs +prepfile("\xEF") +NoRun("unexpected symbol", 'lua %s > %s', prog, out) + +prepfile("\xEF\xBB") +NoRun("unexpected symbol", 'lua %s > %s', prog, out) + +prepfile("\xEFprint(3)") +NoRun("unexpected symbol", 'lua %s > %s', prog, out) + +prepfile("\xEF\xBBprint(3)") +NoRun("unexpected symbol", 'lua %s > %s', prog, out) + + -- test option '-' RUN('echo "print(arg[1])" | lua - -h > %s', out) checkout("-h\n") @@ -385,12 +412,10 @@ checkprogout("101\n13\t22\n\n") prepfile[[#comment in 1st line without \n at the end]] RUN('lua %s', prog) -prepfile[[#test line number when file starts with comment line -debug = require"debug" -print(debug.getinfo(1).currentline) -]] +-- first-line comment with binary file +prepfile("#comment\n" .. string.dump(load("print(3)"))) RUN('lua %s > %s', prog, out) -checkprogout('3\n') +checkout('3\n') -- close Lua with an open file prepfile(string.format([[io.output(%q); io.write('alo')]], out)) -- cgit v1.2.3-55-g6feb