diff options
Diffstat (limited to 'src/test/njs_unit_test.c')
-rw-r--r-- | src/test/njs_unit_test.c | 126 |
1 files changed, 117 insertions, 9 deletions
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 2227c0a6..78e12197 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -3923,6 +3923,9 @@ static njs_unit_test_t njs_test[] = { njs_str("delete this !== true"), njs_str("false") }, + { njs_str("undefined[Symbol()]"), + njs_str("TypeError: cannot get property \"Symbol()\" of undefined") }, + /* Object shorthand methods. */ { njs_str("var o = {m(){}}; new o.m();"), @@ -5906,6 +5909,12 @@ static njs_unit_test_t njs_test[] = njs_str("true") }, { njs_str(NJS_TYPED_ARRAY_LIST + ".every(v=>{Object.defineProperty(v.prototype, '0', {set(){ throw 'Oops' }});" + " var t = new v([0]); var r = Object.create(t);" + " r[0] = 1; return true})"), + njs_str("true") }, + + { njs_str(NJS_TYPED_ARRAY_LIST ".every(v=>{try {var a = new v([1,1]); Object.defineProperty(a, '1', {get(){return 22}})} " " catch (e) { return e.message == 'Cannot redefine property: \"1\"'}})"), njs_str("true") }, @@ -9553,6 +9562,9 @@ static njs_unit_test_t njs_test[] = { njs_str("/["), njs_str("SyntaxError: Unterminated RegExp \"/[\" in 1") }, + { njs_str("/[][a"), + njs_str("SyntaxError: Unterminated RegExp \"/[][a\" in 1") }, + { njs_str("/[\\"), njs_str("SyntaxError: Unterminated RegExp \"/[\\\" in 1") }, @@ -9588,11 +9600,24 @@ static njs_unit_test_t njs_test[] = njs_str("/\\]cd/") }, #endif + { njs_str("RegExp('[][a')"), + njs_str("SyntaxError: " + njs_pcre_var("pcre_compile2(\"(?!)[a\") failed: missing terminating ] for character class at \"\"", + "pcre_compile(\"[][a\") failed: missing terminating ] for character class")) }, + + { njs_str("RegExp('[][a][a')"), + njs_str("SyntaxError: " + njs_pcre_var("pcre_compile2(\"(?!)[a][a\") failed: missing terminating ] for character class at \"\"", + "pcre_compile(\"[][a][a\") failed: missing terminating ] for character class")) }, + { njs_str("RegExp('[\\\\')"), njs_str("SyntaxError: " njs_pcre_var("pcre_compile2(\"[\\\") failed: \\ at end of pattern at \"\"", "pcre_compile(\"[\\\") failed: \\ at end of pattern")) }, + { njs_str("RegExp('[][a]')"), + njs_str(njs_pcre_var("/(?!)[a]/", "/[][a]/")) }, + { njs_str("RegExp('\\\\0').source[1]"), njs_str("0") }, @@ -10984,6 +11009,30 @@ static njs_unit_test_t njs_test[] = "f.apply(123, {})"), njs_str("123") }, + { njs_str("'Hello'.concat(' ', 'World')"), + njs_str("Hello World") }, + + { njs_str("'Value: '.concat(42, ' and ', 3.14)"), + njs_str("Value: 42 and 3.14") }, + + { njs_str("'Flags: '.concat(true, ' and ', false)"), + njs_str("Flags: true and false") }, + + { njs_str("'Values: '.concat(null, ' and ', undefined)"), + njs_str("Values: null and undefined") }, + + { njs_str("'Mixed: '.concat(123, ' ', true, ' ', null, ' ', undefined)"), + njs_str("Mixed: 123 true null undefined") }, + + { njs_str("'Special: '.concat(NaN, ' ', Infinity, ' ', -Infinity)"), + njs_str("Special: NaN Infinity -Infinity") }, + + { njs_str("'Numbers: '.concat(1234567890, ' ', 0.123456789, ' ', 1.23e-10)"), + njs_str("Numbers: 1234567890 0.123456789 1.23e-10") }, + + { njs_str("'Zero: '.concat(0, ' ', -0)"), + njs_str("Zero: 0 0") }, + { njs_str("(function(index, ...rest){ return rest[index];})" ".apply({}, [1022].concat(Array(1023).fill(1).map((v,i)=>i.toString(16))))"), njs_str("3fe") }, @@ -11033,6 +11082,15 @@ static njs_unit_test_t njs_test[] = { njs_str("''.concat.apply('a', [ 'b', 'c' ], 'd')"), njs_str("abc") }, + { njs_str("''.concat.apply('', Array(128).fill(1.23456789123e14)) == '123456789123000'.repeat(128)"), + njs_str("true") }, + + { njs_str("''.concat.apply('', Array(128).fill(0).map((v,i)=>Math.log2(i))).startsWith('-Infinity')"), + njs_str("true") }, + + { njs_str("''.concat.apply('', Array(256).fill(0).map((v,i)=> !(i % 2) ? Math.exp(i) : 'α'.repeat(Math.log2(i)))).endsWith('110ααααααα')"), + njs_str("true") }, + { njs_str("[].join.call([1,2,3])"), njs_str("1,2,3") }, @@ -11966,6 +12024,48 @@ static njs_unit_test_t njs_test[] = { njs_str("/[]a/.test('a')"), njs_str("false") }, + { njs_str("/[#[]/.test('[')"), + njs_str("true") }, + + { njs_str("/[\\s[]/.test('[')"), + njs_str("true") }, + + { njs_str("/[#[^]/.test('[')"), + njs_str("true") }, + + { njs_str("/[#\\[]/.test('[')"), + njs_str("true") }, + + { njs_str("/[\\[^]/.test('[')"), + njs_str("true") }, + + { njs_str("/[^]abc]/.test('#abc]')"), + njs_str("true") }, + + { njs_str("/[[^]abc]/.test('[abc]')"), + njs_str("true") }, + + { njs_str("/[[^]abc]/.test('^abc]')"), + njs_str("true") }, + + { njs_str("/[]/.test('[]')"), + njs_str("false") }, + + { njs_str("/[[]/.test('[')"), + njs_str("true") }, + + { njs_str("/\\[]/.test('[]')"), + njs_str("true") }, + + { njs_str("/[]abc]/.test('abc]')"), + njs_str("false") }, + + { njs_str("/abc]/.test('abc]')"), + njs_str("true") }, + + { njs_str("/\\\\\\[]/.test('\\\\[]')"), + njs_str("true") }, + #ifdef NJS_HAVE_PCRE2 { njs_str("/[]*a/.test('a')"), njs_str("true") }, @@ -14186,22 +14286,22 @@ static njs_unit_test_t njs_test[] = njs_str("true") }, { njs_str("new Function('('.repeat(2**13));"), - njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") }, + njs_str("SyntaxError: Unexpected token \"}\" in runtime") }, { njs_str("new Function('{'.repeat(2**13));"), - njs_str("SyntaxError: Unexpected token \")\" in runtime:1") }, + njs_str("SyntaxError: Unexpected token \")\" in runtime") }, { njs_str("new Function('['.repeat(2**13));"), - njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") }, + njs_str("SyntaxError: Unexpected token \"}\" in runtime") }, { njs_str("new Function('`'.repeat(2**13));"), njs_str("[object Function]") }, { njs_str("new Function('{['.repeat(2**13));"), - njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") }, + njs_str("SyntaxError: Unexpected token \"}\" in runtime") }, { njs_str("new Function('{;'.repeat(2**13));"), - njs_str("SyntaxError: Unexpected token \")\" in runtime:1") }, + njs_str("SyntaxError: Unexpected token \")\" in runtime") }, { njs_str("(new Function('1;'.repeat(2**13) + 'return 2'))()"), njs_str("2") }, @@ -14213,7 +14313,7 @@ static njs_unit_test_t njs_test[] = njs_str("-4") }, { njs_str("new Function('new '.repeat(2**13));"), - njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") }, + njs_str("SyntaxError: Unexpected token \"}\" in runtime") }, { njs_str("(new Function('return ' + 'typeof '.repeat(2**13) + 'x'))()"), njs_str("string") }, @@ -14279,7 +14379,13 @@ static njs_unit_test_t njs_test[] = njs_str("ReferenceError: \"foo\" is not defined") }, { njs_str("this.NN = {}; var f = Function('eval = 42;'); f()"), - njs_str("SyntaxError: Identifier \"eval\" is forbidden as left-hand in assignment in runtime:1") }, + njs_str("SyntaxError: Identifier \"eval\" is forbidden as left-hand in assignment in runtime") }, + + { njs_str("new Function('}); let a; a; function o(){}; //')"), + njs_str("SyntaxError: Unexpected token \"}\" in runtime") }, + + { njs_str("new Function('}); let a; a; function o(){}; ({')"), + njs_str("SyntaxError: single function literal required") }, { njs_str("RegExp()"), njs_str("/(?:)/") }, @@ -19808,7 +19914,7 @@ static njs_unit_test_t njs_test[] = njs_str("[object AsyncFunction]") }, { njs_str("let f = new Function('x', 'await 1; return x'); f(1)"), - njs_str("SyntaxError: await is only valid in async functions in runtime:1") }, + njs_str("SyntaxError: await is only valid in async functions in runtime") }, { njs_str("new AsyncFunction()"), njs_str("ReferenceError: \"AsyncFunction\" is not defined") }, @@ -21673,7 +21779,9 @@ done: return NJS_ERROR; } - success = njs_strstr_eq(&expected->ret, &s); + success = expected->ret.length <= s.length + && (memcmp(expected->ret.start, s.start, expected->ret.length) + == 0); if (!success) { njs_stderror("njs(\"%V\")\nexpected: \"%V\"\n got: \"%V\"\n", &expected->script, &expected->ret, &s); |