Skip to content

Commit

Permalink
Tests for delete operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ShortDevelopment committed Dec 27, 2024
1 parent 835a4fa commit 72aac4a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/es12/optional-delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

// @ts-check
/// <reference path="../UnitTestFramework/UnitTestFramework.js" />

WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");

const createObj = () => ({ "null": null, "undefined": undefined, something: 42 });

const tests = [
{
name: "`delete` should successfully delete from opt-chain",
body() {
const obj = createObj();

assert.strictEqual(null, obj?.null);
assert.isTrue(delete obj?.null);
assert.strictEqual(undefined, obj?.null);

assert.strictEqual(undefined, obj?.undefined);
assert.isTrue(delete obj?.undefined);
assert.strictEqual(undefined, obj?.undefined);

assert.strictEqual(42, obj?.something);
assert.isTrue(delete obj?.something);
assert.strictEqual(undefined, obj?.something);
}
},
{
name: "`delete` should return `true` if opt-chain short-circuits",
body() {
const obj = createObj();

assert.strictEqual(undefined, obj.doesNotExist);
assert.strictEqual(undefined, obj.doesNotExist?.something);
assert.isTrue(delete obj.doesNotExist?.something);
assert.strictEqual(undefined, obj.doesNotExist?.something);

assert.strictEqual(undefined, obj?.doesNotExist);
assert.strictEqual(undefined, obj?.doesNotExist?.something);
assert.isTrue(delete obj?.doesNotExist?.something);
assert.strictEqual(undefined, obj?.doesNotExist?.something);
}
}
];

testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
4 changes: 4 additions & 0 deletions test/es12/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
<files>optional-async.js</files>
<compile-flags>-args summary -endargs</compile-flags>
</default>
<default>
<files>optional-delete.js</files>
<compile-flags>-args summary -endargs</compile-flags>
</default>
</test>
</regress-exe>

0 comments on commit 72aac4a

Please sign in to comment.