memset_invariant.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. this.WScript.LoadScriptFile(".\\memset_tester.js");
  6. const allTypes = [0, 1.5, undefined, null, 9223372036854775807, "string", {a: null, b: "b"}];
  7. const tests = [
  8. {name: "memsetUndefined", stringValue: undefined},
  9. {name: "memsetNull", stringValue: null},
  10. {name: "memsetInt", stringValue: 0, v2: 1 << 30},
  11. {name: "memsetFloat", stringValue: 3.14, v2: -87.684},
  12. {name: "memsetNumber", stringValue: 9223372036854775807, v2: -987654987654987},
  13. {name: "memsetBoolean", stringValue: true, v2: false},
  14. {name: "memsetString", stringValue: "\"thatString\"", v2: "`A template string`"},
  15. {name: "memsetObject", stringValue: "{test: 1}", v2: [1, 2, 3]},
  16. ];
  17. const types = "Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Array".split(" ");
  18. let passed = RunMemsetTest(tests, types, allTypes);
  19. function memsetSymbol() {const s = Symbol(); const arr = new Array(10); for(let i = 0; i < 10; ++i) {arr[i] = s;} return arr;}
  20. function memsetSymbolV(v) {const arr = new Array(10); for(let i = 0; i < 10; ++i) {arr[i] = v;} return arr;}
  21. function checkSymbols() {
  22. const s = Symbol();
  23. // Since symbol are unique, and we want to compare the result, we have to pass the same symbol everytime
  24. const a1 = memsetSymbolV(s);
  25. const a2 = memsetSymbolV(s);
  26. for(let i = 0; i < a1.length; ++i) {
  27. if(a1[i] !== a2[i]) {
  28. passed = false;
  29. // need explicit toString() for Symbol
  30. print(`memsetSymbolV: a1[${i}](${a1[i].toString()}) != a2[${i}](${a2 && a2[i].toString() || ""})`);
  31. break;
  32. }
  33. }
  34. memsetSymbol();
  35. const symbolArray = memsetSymbol();
  36. for(let i = 0; i < symbolArray.length; ++i) {
  37. if(typeof symbolArray[i] !== typeof s) {
  38. passed = false;
  39. print(`memsetSymbol: symbolArray[${i}] is not a Symbol`);
  40. break;
  41. }
  42. }
  43. }
  44. checkSymbols();
  45. print(passed ? "PASSED" : "FAILED");