How to use testPairs method in wpt

Best JavaScript code snippet using wpt

testAuth.ts

Source:testAuth.ts Github

copy

Full Screen

1import test from 'tape-promise/tape'2import { TokenSigner } from 'jsontokens'3import * as auth from '../../src/server/authentication'4import * as errors from '../../src/server/errors'5import { testPairs, testAddrs} from './common'6export function testAuth() {7 test('authentication legacy/regression', (t) => {8 const legacyPart = {9 wif: 'Kzp44Hhp6SFUXMuMi6MUDTqyfcNyyjntrphEHVMsiitRrjMyoV4p',10 addr: '1AotVNASQouiNiBtfxv49WWvSNcQUzGYuU',11 serverName: 'storage.aladin.org',12 legacyAuth: 'eyJwdWJsaWNrZXkiOiIwMjQxYTViMDQ2Mjg1ZjVlMjgwMDRmOTJjY2M0MjNmY2RkODYyZmYzY' +13 'jgwODUwNzE4MDY4MGIyNDA3ZTIyOWE3NzgiLCJzaWduYXR1cmUiOiIzMDQ0MDIyMDY5ODUwNmNjYjg3MDg1Zm' +14 'Y5ZGI3ZTc4MTIwYTVmMjY1YzExZmY0ODc4OTBlNDQ1MWZjYWM3NjA4NTkyMDhjZWMwMjIwNTZkY2I0OGUyYzE' +15 '4Y2YwZjQ1NDZiMmQ3M2I2MDY4MWM5ODEyMzQyMmIzOTRlZjRkMWI2MjE3NTYyODQ4MzUwNCJ9' }16 t.doesNotThrow(() => auth.validateAuthorizationHeader(`bearer ${legacyPart.legacyAuth}`,17 legacyPart.serverName,18 legacyPart.addr),19 'legacy authentication token should work')20 t.end()21 })22 test('authentication legacy/regression with multi-case bearer', (t) => {23 const legacyPart = {24 wif: 'Kzp44Hhp6SFUXMuMi6MUDTqyfcNyyjntrphEHVMsiitRrjMyoV4p',25 addr: '1AotVNASQouiNiBtfxv49WWvSNcQUzGYuU',26 serverName: 'storage.aladin.org',27 legacyAuth: 'eyJwdWJsaWNrZXkiOiIwMjQxYTViMDQ2Mjg1ZjVlMjgwMDRmOTJjY2M0MjNmY2RkODYyZmYzY' +28 'jgwODUwNzE4MDY4MGIyNDA3ZTIyOWE3NzgiLCJzaWduYXR1cmUiOiIzMDQ0MDIyMDY5ODUwNmNjYjg3MDg1Zm' +29 'Y5ZGI3ZTc4MTIwYTVmMjY1YzExZmY0ODc4OTBlNDQ1MWZjYWM3NjA4NTkyMDhjZWMwMjIwNTZkY2I0OGUyYzE' +30 '4Y2YwZjQ1NDZiMmQ3M2I2MDY4MWM5ODEyMzQyMmIzOTRlZjRkMWI2MjE3NTYyODQ4MzUwNCJ9' }31 t.doesNotThrow(() => auth.validateAuthorizationHeader(`BeArEr ${legacyPart.legacyAuth}`,32 legacyPart.serverName,33 legacyPart.addr),34 'legacy authentication token should work')35 t.end()36 })37 test('storage validation', (t) => {38 const challengeText = auth.getChallengeText()39 const authPart = auth.LegacyAuthentication.makeAuthPart(testPairs[0], challengeText)40 const authorization = `bearer ${authPart}`41 const authenticator = auth.parseAuthHeader(authorization)42 t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),43 errors.ValidationError, 'Wrong address must throw')44 t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos']),45 errors.ValidationError, 'Wrong challenge text must throw')46 t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),47 'Good signature must pass')48 t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),49 'Bad signature must throw')50 t.end()51 })52 test('v1 storage validation', (t) => {53 const challengeText = 'bananas are tasty'54 const authPart = auth.V1Authentication.makeAuthPart(testPairs[0], challengeText)55 console.log(`V1 storage validation: ${authPart}`)56 const authorization = `bearer ${authPart}`57 const authenticator = auth.parseAuthHeader(authorization)58 t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),59 errors.ValidationError, 'Wrong address must throw')60 t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos are tasty']),61 errors.ValidationError, 'Wrong challenge text must throw')62 t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),63 'Good signature must pass')64 // signer address was from the v1 token65 t.equal(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]), testAddrs[0])66 const signerKeyHex = testPairs[0].privateKey.toString('hex')67 const tokenWithoutIssuer = new TokenSigner('ES256K', signerKeyHex).sign(68 { garbage: 'in' })69 const goodTokenWithoutExp = new TokenSigner('ES256K', signerKeyHex).sign(70 { gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex') })71 const expiredToken = new TokenSigner('ES256K', signerKeyHex).sign(72 { gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex'), exp: 1 })73 const wrongIssuerToken = new TokenSigner('ES256K', signerKeyHex).sign(74 { gaiaChallenge: challengeText, iss: testPairs[1].publicKey.toString('hex'), exp: 1 })75 t.throws(() => new auth.V1Authentication(tokenWithoutIssuer).isAuthenticationValid(testAddrs[0], [challengeText]),76 errors.ValidationError, 'No `iss`, should fail')77 t.throws(() => new auth.V1Authentication(expiredToken).isAuthenticationValid(testAddrs[0], [challengeText]),78 errors.ValidationError, 'Expired token should fail')79 t.throws(() => new auth.V1Authentication(wrongIssuerToken).isAuthenticationValid(testAddrs[1], [challengeText]),80 errors.ValidationError, 'Invalid signature')81 t.ok(new auth.V1Authentication(goodTokenWithoutExp).isAuthenticationValid(testAddrs[0], [challengeText]),82 'Valid token without expiration should pass')83 t.end()84 })85 test('v1 storage validation with hubUrls required', (t) => {86 const challengeText = 'bananas are tasty'87 const authPart = auth.V1Authentication.makeAuthPart(testPairs[0], challengeText)88 console.log(`V1 storage validation: ${authPart}`)89 const authorization = `bearer ${authPart}`90 const authenticator = auth.parseAuthHeader(authorization)91 t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),92 errors.ValidationError, 'Wrong address must throw')93 t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos are tasty']),94 errors.ValidationError, 'Wrong challenge text must throw')95 t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),96 'Good signature must pass')97 // signer address was from the v1 token98 t.equal(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]), testAddrs[0])99 const signerKeyHex = testPairs[0].privateKey.toString('hex')100 const tokenWithoutIssuer = new TokenSigner('ES256K', signerKeyHex).sign(101 { garbage: 'in' })102 const goodTokenWithoutExp = new TokenSigner('ES256K', signerKeyHex).sign(103 { gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex') })104 const expiredToken = new TokenSigner('ES256K', signerKeyHex).sign(105 { gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex'), exp: 1 })106 const wrongIssuerToken = new TokenSigner('ES256K', signerKeyHex).sign(107 { gaiaChallenge: challengeText, iss: testPairs[1].publicKey.toString('hex'), exp: 1 })108 t.throws(() => new auth.V1Authentication(tokenWithoutIssuer).isAuthenticationValid(testAddrs[0], [challengeText]),109 errors.ValidationError, 'No `iss`, should fail')110 t.throws(() => new auth.V1Authentication(expiredToken).isAuthenticationValid(testAddrs[0], [challengeText]),111 errors.ValidationError, 'Expired token should fail')112 t.throws(() => new auth.V1Authentication(wrongIssuerToken).isAuthenticationValid(testAddrs[1], [challengeText]),113 errors.ValidationError, 'Invalid signature')114 t.ok(new auth.V1Authentication(goodTokenWithoutExp).isAuthenticationValid(testAddrs[0], [challengeText]),115 'Valid token without expiration should pass')116 t.end()117 })118 test('v1 storage validation with association token', (t) => {119 const challengeText = 'bananas are tasty'120 const associationToken = auth.V1Authentication.makeAssociationToken(testPairs[1], testPairs[0].publicKey.toString('hex'))121 const authPart = auth.V1Authentication.makeAuthPart(testPairs[0], challengeText, associationToken)122 console.log(`V1 storage validation: ${authPart}`)123 const authorization = `bearer ${authPart}`124 const authenticator = auth.parseAuthHeader(authorization)125 t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),126 errors.ValidationError, 'Wrong address must throw')127 t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos are tasty']),128 errors.ValidationError, 'Wrong challenge text must throw')129 t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),130 'Good signature must pass')131 // signer address was from the association token132 t.equal(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]), testAddrs[1])133 // failures should work the same if the outer JWT is invalid134 const signerKeyHex = testPairs[0].privateKey.toString('hex')135 const tokenWithoutIssuer = new TokenSigner('ES256K', signerKeyHex).sign(136 { garbage: 'in' })137 const goodTokenWithoutExp = new TokenSigner('ES256K', signerKeyHex).sign(138 { gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex') })139 const expiredToken = new TokenSigner('ES256K', signerKeyHex).sign(140 { gaiaChallenge: challengeText, iss: testPairs[0].publicKey.toString('hex'), exp: 1 })141 const wrongIssuerToken = new TokenSigner('ES256K', signerKeyHex).sign(142 { gaiaChallenge: challengeText, iss: testPairs[1].publicKey.toString('hex'), exp: 1 })143 t.throws(() => new auth.V1Authentication(tokenWithoutIssuer).isAuthenticationValid(testAddrs[0], [challengeText]),144 errors.ValidationError, 'No `iss`, should fail')145 t.throws(() => new auth.V1Authentication(expiredToken).isAuthenticationValid(testAddrs[0], [challengeText]),146 errors.ValidationError, 'Expired token should fail')147 t.throws(() => new auth.V1Authentication(wrongIssuerToken).isAuthenticationValid(testAddrs[1], [challengeText]),148 errors.ValidationError, 'Invalid signature')149 t.ok(new auth.V1Authentication(goodTokenWithoutExp).isAuthenticationValid(testAddrs[0], [challengeText]),150 'Valid token without expiration should pass')151 // invalid associationTokens should cause a well-formed outer JWT to fail authentication152 const ownerKeyHex = testPairs[0].privateKey.toString('hex')153 const associationTokenWithoutIssuer = new TokenSigner('ES256K', ownerKeyHex).sign(154 { garbage: 'in' })155 const associationTokenWithoutExp = new TokenSigner('ES256K', ownerKeyHex).sign(156 { childToAssociate: testPairs[1].publicKey.toString('hex'), iss: testPairs[0].publicKey.toString('hex') })157 const expiredAssociationToken = new TokenSigner('ES256K', ownerKeyHex).sign(158 { childToAssociate: testPairs[1].publicKey.toString('hex'), iss: testPairs[0].publicKey.toString('hex'), exp: 1 })159 const wrongIssuerAssociationToken = new TokenSigner('ES256K', ownerKeyHex).sign(160 { childToAssociate: testPairs[1].publicKey.toString('hex'), iss: testPairs[1].publicKey.toString('hex'), exp: (Date.now()/1000) * 2 })161 const wrongBearerAddressAssociationToken = new TokenSigner('ES256K', ownerKeyHex).sign(162 { childToAssociate: testPairs[0].publicKey.toString('hex'), iss: testPairs[0].publicKey.toString('hex'), exp: (Date.now()/1000) * 2 })163 function makeAssocAuthToken(keypair, ct, assocJWT) {164 return new auth.V1Authentication(auth.V1Authentication.fromAuthPart(auth.V1Authentication.makeAuthPart(keypair, ct, assocJWT)).token)165 }166 t.throws(() => makeAssocAuthToken(testPairs[1], challengeText, associationTokenWithoutIssuer).isAuthenticationValid(testAddrs[1], [challengeText]),167 errors.ValidationError, 'No `iss` in association token, should fail')168 t.throws(() => makeAssocAuthToken(testPairs[1], challengeText, associationTokenWithoutExp).isAuthenticationValid(testAddrs[1], [challengeText]),169 errors.ValidationError, 'Association token without exp should fail')170 t.throws(() => makeAssocAuthToken(testPairs[1], challengeText, expiredAssociationToken).isAuthenticationValid(testAddrs[1], [challengeText]),171 errors.ValidationError, 'Expired association token should fail')172 t.throws(() => makeAssocAuthToken(testPairs[1], challengeText, wrongIssuerAssociationToken).isAuthenticationValid(testAddrs[1], [challengeText]),173 errors.ValidationError, 'Wrong association token issuer, should fail')174 t.throws(() => makeAssocAuthToken(testPairs[1], challengeText, wrongBearerAddressAssociationToken).isAuthenticationValid(testAddrs[1], [challengeText]),175 errors.ValidationError, 'Wrong bearer address for association token, should fail')176 t.end()177 })178 test('v1 storage validation with scoped authentication token', (t) => {179 const challengeText = 'bananas are tasty'180 const writeScopes = [181 {182 scope: 'putFile',183 domain: '/foo/bar',184 },185 {186 scope: 'putFile',187 domain: '/baz'188 }189 ]190 const writeScopesInvalid = [191 {192 scope: 'invalid',193 domain: 'nope',194 }195 ]196 const writeScopesTooLong = [197 {198 scope: 'putFile',199 domain: '/0',200 },201 {202 scope: 'putFile',203 domain: '/1'204 },205 {206 scope: 'putFile',207 domain: '/2'208 },209 {210 scope: 'putFile',211 domain: '/3'212 },213 {214 scope: 'putFile',215 domain: '/4'216 },217 {218 scope: 'putFile',219 domain: '/5'220 },221 {222 scope: 'putFile',223 domain: '/6'224 },225 {226 scope: 'putFile',227 domain: '/7'228 },229 {230 scope: 'putFile',231 domain: '/8'232 }233 ]234 const authPart = auth.V1Authentication.makeAuthPart(testPairs[0], challengeText, undefined, undefined, writeScopes)235 console.log(`V1 storage validation: ${authPart}`)236 const authorization = `bearer ${authPart}`237 const authenticator = auth.parseAuthHeader(authorization)238 t.throws(() => authenticator.isAuthenticationValid(testAddrs[1], [challengeText]),239 errors.ValidationError, 'Wrong address must throw')240 t.throws(() => authenticator.isAuthenticationValid(testAddrs[0], ['potatos are tasty']),241 errors.ValidationError, 'Wrong challenge text must throw')242 t.ok(authenticator.isAuthenticationValid(testAddrs[0], [challengeText]),243 'Good signature must pass')244 // scopes must be present245 const authScopes = authenticator.getAuthenticationScopes()246 t.equal(authScopes[0].scope, 'putFile', 'scope 0 is putfile')247 t.equal(authScopes[0].domain, '/foo/bar', 'scope 0 is for /foo/bar')248 t.equal(authScopes[1].scope, 'putFile', 'scope 1 is putfile')249 t.equal(authScopes[1].domain, '/baz', 'scope 1 is for /baz')250 // invalid scopes must not be allowed251 t.throws(() => auth.V1Authentication.makeAuthPart(testPairs[0], challengeText, undefined, undefined, writeScopesTooLong),252 errors.ValidationError, 'Too many scopes must throw')253 t.throws(() => auth.V1Authentication.makeAuthPart(testPairs[0], challengeText, undefined, undefined, writeScopesInvalid),254 errors.ValidationError, 'Invalid scopes must throw')255 t.end()256 })...

Full Screen

Full Screen

test_encode.js

Source:test_encode.js Github

copy

Full Screen

1// returns a list of [string, object] pairs to test encoding2function getTestPairs() {3 var testPairs = [4 ["{}", {}],5 ["[]", []],6 ['{"foo":"bar"}', {"foo":"bar"}],7 ['{"null":null}', {"null":null}],8 ['{"five":5}', {"five":5}],9 ['{"five":5,"six":6}', {"five":5, "six":6}],10 ['{"x":{"y":"z"}}', {"x":{"y":"z"}}],11 ['{"w":{"x":{"y":"z"}}}', {"w":{"x":{"y":"z"}}}],12 ['[1,2,3]', [1,2,3]],13 ['{"w":{"x":{"y":[1,2,3]}}}', {"w":{"x":{"y":[1,2,3]}}}],14 ['{"false":false}', {"false":false}],15 ['{"true":true}', {"true":true}],16 ['{"child has two members":{"this":"one","2":"and this one"}}',17 {"child has two members": {"this":"one", 2:"and this one"}}],18 ['{"x":{"a":"b","c":{"y":"z"},"f":"g"}}',19 {"x":{"a":"b","c":{"y":"z"},"f":"g"}}],20 ['{"x":[1,{"y":"z"},3]}', {"x":[1,{"y":"z"},3]}],21 //['{"0":"h","1":"m","2":"m"}', new String("hmm")],22 ['[1,null,3]',[1,,3]],23 [null, function test(){}],24 [null, dump],25 ['{"mm\\\"mm":"hmm"}',{"mm\"mm":"hmm"}],26 ['{"mm\\\"mm\\\"mm":"hmm"}',{"mm\"mm\"mm":"hmm"}],27 ['{"\\\"":"hmm"}',{'"':"hmm"}],28 ['{"\\\\":"hmm"}',{'\\':"hmm"}],29 ['{"mmm\\\\mmm":"hmm"}',{'mmm\\mmm':"hmm"}],30 ['{"mmm\\\\mmm\\\\mmm":"hmm"}',{'mmm\\mmm\\mmm':"hmm"}],31 ['{"mm\\u000bmm":"hmm"}',{"mm\u000bmm":"hmm"}],32 ['{"mm\\u0000mm":"hmm"}',{"mm\u0000mm":"hmm"}]33 ];34 var x = {"free":"variable"}35 testPairs.push(['{"free":"variable"}', x]);36 testPairs.push(['{"y":{"free":"variable"}}', {"y":x}]);37 // array prop38 var x = {39 a: [1,2,3]40 }41 testPairs.push(['{"a":[1,2,3]}', x])42 var y = {43 foo: function(hmm) { return hmm; }44 }45 testPairs.push(['{"y":{}}',{"y":y}]);46 // test toJSON47 var hmm = {48 toJSON: function() { return {"foo":"bar"}}49 }50 testPairs.push(['{"hmm":{"foo":"bar"}}', {"hmm":hmm}]);51 testPairs.push(['{"foo":"bar"}', hmm]); // on the root52 // toJSON on prototype53 var Y = function() {54 this.d = "e";55 }56 Y.prototype = {57 not:"there?",58 toJSON: function() { return {"foo":"bar"}}59 };60 var y = new Y();61 testPairs.push(['{"foo":"bar"}', y.toJSON()]);62 testPairs.push(['{"foo":"bar"}', y]);63 // return undefined from toJSON64 var hmm = {65 toJSON: function() { return; }66 }67 testPairs.push(['{}', {"hmm":hmm}]);68 // array with named prop69 var x= new Array();70 x[0] = 1;71 x.foo = "bar";72 //testPairs.push(['[1]', x]);73 // prototype74 var X = function() { this.a = "b" }75 X.prototype = {c:"d"}76 var y = new X();77 testPairs.push(['{"a":"b","c":"d"}', y]);78 // useless roots will be dropped79 testPairs.push([null, null]);80 testPairs.push([null, ""]);81 testPairs.push([null, undefined]);82 testPairs.push([null, 5]);83 // custom iterator: JS 1.7+84 var x = {85 "a": "foo",86 b: "not included",87 c: "bar",88 "4": "qux",89 __iterator__: function() { return (function() { yield "a"; yield "c"; yield 4; })() }90 }91 do_check_eq('{"a":"foo","c":"bar","4":"qux"}', nativeJSON.encode(x));92 return testPairs;93}94function testStringEncode() {95 // test empty arg96 do_check_eq(null, nativeJSON.encode());97 var pairs = getTestPairs();98 for each(pair in pairs) {99 var nativeResult = nativeJSON.encode(pair[1]);100 var crockfordResult = JSON.stringify(pair[1]);101 do_check_eq(pair[0], nativeResult);102 103 // Don't follow json2.js handling of non-objects104 if (pair[1] && (typeof pair[1] == "object")) {105 do_check_eq(crockfordResult, nativeResult);106 }107 }108}109function testOutputStreams() {110 function writeToFile(obj, charset, writeBOM) {111 var jsonFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);112 jsonFile.initWithFile(outputDir);113 jsonFile.append("test.json");114 jsonFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);115 var stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);116 try {117 stream.init(jsonFile, 0x04 | 0x08 | 0x20, 0600, 0); // write, create, truncate118 nativeJSON.encodeToStream(stream, charset, writeBOM, obj);119 } finally {120 stream.close();121 }122 return jsonFile;123 }124 var pairs = getTestPairs();125 for each(pair in pairs) {126 if (pair[1] && (typeof pair[1] == "object")) {127 var utf8File = writeToFile(pair[1], "UTF-8", false);128 var utf16LEFile = writeToFile(pair[1], "UTF-16LE", false);129 var utf16BEFile = writeToFile(pair[1], "UTF-16BE", false);130 var utf32LEFile = writeToFile(pair[1], "UTF-32LE", false);131 var utf32BEFile = writeToFile(pair[1], "UTF-32BE", false);132 // all ascii with no BOMs, so this will work133 do_check_eq(utf16LEFile.fileSize / 2, utf8File.fileSize);134 do_check_eq(utf32LEFile.fileSize / 4, utf8File.fileSize);135 do_check_eq(utf16LEFile.fileSize, utf16BEFile.fileSize);136 do_check_eq(utf32LEFile.fileSize, utf32BEFile.fileSize);137 }138 }139 // check BOMs140 var f = writeToFile({},"UTF-8", true);141 do_check_eq(f.fileSize, 5);142 var f = writeToFile({},"UTF-16LE", true);143 do_check_eq(f.fileSize, 6);144 var f = writeToFile({},"UTF-16BE", true);145 do_check_eq(f.fileSize, 6);146 var f = writeToFile({},"UTF-32LE", true);147 do_check_eq(f.fileSize, 12);148 var f = writeToFile({},"UTF-32BE", true);149 do_check_eq(f.fileSize, 12);150 151 outputDir.remove(true);152}153function throwingToJSON() {154 var a = {155 "b": 1,156 "c": 2,157 toJSON: function() { throw("uh oh"); }158 }159 try {160 var y = nativeJSON.encode(a);161 } catch (ex) {}162}163function throwingIterator() {164 var a = {165 "b": 1,166 "c": 2,167 __iterator__: function() { yield "b"; throw("uh oh"); }168 }169 try {170 var y = nativeJSON.encode(a);171 } catch (ex) {}172}173function deletingIter(x) {174 return function() {175 yield "dd";176 print("after first yield");177 delete x["a"]["c"];178 gc();179 print("about to yield second");180 yield "ddddd";181 }182}183function deleteDuringEncode() {184 var x = {};185 x.a = {186 b: 1,187 bb: 2,188 bbb: 3,189 c: {190 cc: 2,191 ccc: 3,192 d: {193 dd: 2,194 ddd: 3,195 __iterator__: deletingIter(x),196 dddd: 4,197 ddddd: 5198 },199 cccc: 4,200 ccccc: 5201 },202 bbbb: 4,203 bbbbb: 5,204 bbbbbb: 6205 };206 var z = nativeJSON.encode(x);207 print(z);208}209function run_test() {210 testStringEncode();211 throwingToJSON();212 throwingIterator();213 deleteDuringEncode();214 215 // failing on windows -- bug 410005216 // testOutputStreams();217 ...

Full Screen

Full Screen

known-issues.js

Source:known-issues.js Github

copy

Full Screen

1const expect = require('chai').expect;2const RiTa = require('../src/rita');3describe('RiScript.KnownIssues', () => { // TODO:4 it('Should resolve global functions in context', () => {5 let rs = '$player.name has $timer() secs left.';6 let gameState = {7 player: {8 name: 'Wing',9 color: 'blue',10 traits: []11 },12 timer: () => new Date().getSeconds()13 };14 let res = RiTa.evaluate(rs, gameState);15 console.log(res);16 expect(/Wing has [0-9]{1,2} secs left/.test(res)).true;17 });18 it('Should handle complex inlines in grammars', () => {19 let rg, rs;20 rg = new RiGrammar({21 "start": "($chosen=$person) talks to $chosen.",22 "person": "Dave | Jill | Pete"23 });24 rs = rg.expand({ trace: 0 });25 //console.log(rs);26 expect(rs).to.be.oneOf(["Dave talks to Dave.", "Jill talks to Jill.", "Pete talks to Pete."]);27 rg = new RiGrammar({28 "start": "($chosen=$person) talks to $chosen.",29 "person": "$Dave | $Jill | $Pete",30 "Dave": "Dave",31 "Jill": "Jill",32 "Pete": "Pete",33 });34 rs = rg.expand({ trace: 1 });35 expect(rs).to.be.oneOf(["Dave talks to Dave.", "Jill talks to Jill.", "Pete talks to Pete."]);36 });37 it('Should handle RiTa function transforms with args', () => {38 expect(RiTa.evaluate('Is $RiTa.presentPart(lie) wrong?',39 {}, { trace: 1, singlePass: 1 })).eq("Is lying wrong?");40 });41 it('Should throw on infinite recursions', () => { // error-handling42 console.log(RiTa.evaluate('$s', { s: '$a', a: '$s' }));43 expect(() => RiTa.evaluate('$s', { s: '$a', a: '$s' })).to.throw();44 });45 it('Should throw on bad transforms', () => { // error-handling46 expect(() => RiTa.evaluate('a.toUpperCase()', 0, { silent: 1, trace: 1 })).to.throw();47 });48 it('Should eval simple expressions', () => {49 // NOT SURE WHAT THIS TEST IS ABOUT50 expect(RiTa.evaluate('$foo=bar \\nbaz\n$foo', {}, TT)).eq('bar baz'); ``51 });52 it('parse select choices TX', () => {53 let upf = x => x.toLowerCase();54 expect(RiTa.evaluate("(a | a).up()", { up: upf }), { trace: true }).eq("A");55 });56});57describe('RiTa.KnownIssues', () => {58 it('Failing to tag correctly', () => {59 eql(RiTa.pos('as the sun came up and winds from Canada blew down.'), []); // check60 });61 it('Failing to pluralize correctly', () => {62 let testPairs = [ // also in java63 'knives', 'knife'64 // NOTHING NOW65 ];66 let res1, res2, res3, dbug = 0;67 for (let i = 0; i < testPairs.length; i += 2) {68 dbug && console.log(testPairs[i] + '/' + testPairs[i + 1]);69 res1 = RiTa.singularize(testPairs[i], { dbug: dbug });70 res2 = RiTa.pluralize(testPairs[i + 1], { dbug: dbug });71 res3 = RiTa.inflector.isPlural(testPairs[i], { dbug: dbug, fatal: false });72 // singularize73 eq(res1, testPairs[i + 1], 'FAIL: singularize(' + testPairs[i]74 + ') was ' + res1 + ', but expected ' + testPairs[i + 1] + '\n '75 + 'pluralize(' + testPairs[i + 1] + ') was ' + res2 + '\n\n');76 // pluralize77 eq(res2, testPairs[i], 'FAIL: pluralize(' + testPairs[i + 1]78 + ') was ' + res2 + ', but expected ' + testPairs[i] + '\n '79 + 'singularize(' + testPairs[i] + ') was ' + res1 + '\n\n');80 // isPlural81 ok(res3, 'FAIL: isPlural(' + testPairs[i] + ') was false\n\n');82 }83 });84 it('Failing for showing literal dollar sign', () => {85 expect(RiTa.evaluate("This is &#36100", {})).eq("This is $100");86 expect(RiTa.evaluate("This is &#x00024100", {})).eq("This is $100");87 //or maybe some way to seperate &#36 and the digits behind in the Riscript?88 });89});90function eql(output, expected, msg) { expect(output).eql(expected, msg); }91function ok(res, msg) { expect(res).eq(true, msg); }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful