How to use hello method in Kiwi

Best Python code snippet using Kiwi_python

test-html-text-parser.js

Source:test-html-text-parser.js Github

copy

Full Screen

1/*global test, deepEqual, largeModule, strictEqual */2largeModule('HtmlTextParser');3var parser = new cc._Test.HtmlTextParser();4test('Basic Test', function() {5 var testStr1 = "hello world";6 deepEqual(parser.parse(testStr1),7 [{text: "hello world"}],8 'No Html string should be equal to original.');9 var testInvalidStr2 = "<x hello world";10 deepEqual(parser.parse(testInvalidStr2),11 [{text: "x hello world"}],12 'Invalid tag begin.');13 var testInvalidStr1 = "<x>hello world</x>";14 deepEqual(parser.parse(testInvalidStr1),15 [{text: "hello world", style: {}}],16 'Invalid tags');17 var testInvalidStr3 = "</b>hello world";18 deepEqual(parser.parse(testInvalidStr3),19 [{text: "hello world"}],20 "invalid tags end.");21 var testInvalidStr4 = "</>hello world";22 deepEqual(parser.parse(testInvalidStr4),23 [{text: "hello world"}],24 "Empty tags are emitted.");25 var testInvalidStr5 = "<b>hello world";26 deepEqual(parser.parse(testInvalidStr5),27 [{text: "hello world"}],28 "Empty tags are emitted.");29});30test('Color test', function(){31 var colorTestStr1 = "<color=#0xffff00>hello world</color>";32 deepEqual(parser.parse(colorTestStr1),33 [{text: "hello world", style: {color: "#0xffff00"}}],34 "Happy path.");35 var colorTestStr2 = "<color=#0xffff33>hello world</xxx>";36 deepEqual(parser.parse(colorTestStr2),37 [{text: "hello world", style: {color: "#0xffff33"}}],38 "Happy path two.");39 var colorTestStr3 = "<color#0xffff33>hello world</xxx>";40 deepEqual(parser.parse(colorTestStr3),41 [{text: "hello world", style: {}}],42 "Missing the = sign.");43 var colorTestStr4 = "<color=>hello world</xxx>";44 deepEqual(parser.parse(colorTestStr4),45 [{text: "hello world", style: {}}],46 "missing the color value.");47 var colorTestStr5 = "<c=#0xff4400>hello world</xxx>";48 deepEqual(parser.parse(colorTestStr5),49 [{text: "hello world", style: {}}],50 "tag name is invalid");51 var colorTestStr6 = "<color = #0xff4400>hello world";52 deepEqual(parser.parse(colorTestStr6),53 [{text: "hello world"}],54 "The close tag is missing.");55});56test('Size test', function() {57 var sizeTestStr1 = "<size = 20>hello world</size>";58 deepEqual(parser.parse(sizeTestStr1),59 [{text: "hello world", style: {size: 20}}],60 "Happy path 1.");61 var sizeTestStr2 = "<size = 20>hello world</xx>";62 deepEqual(parser.parse(sizeTestStr2),63 [{text: "hello world", style: {size: 20}}],64 "Happy path 2.");65 var sizeTestStr3 = "<size20>hello world</xxx>";66 deepEqual(parser.parse(sizeTestStr3),67 [{text: "hello world", style: {}}],68 "Missing the = sign.");69 var sizeTestStr4 = "<size=>hello world</xxx>";70 deepEqual(parser.parse(sizeTestStr4),71 [{text: "hello world", style: {}}],72 "missing the color value.");73 var sizeTestStr5 = "<s=20>hello world</xxx>";74 deepEqual(parser.parse(sizeTestStr5),75 [{text: "hello world", style: {}}],76 "tag name is invalid");77 var sizeTestStr6 = "<size=20>hello world";78 deepEqual(parser.parse(sizeTestStr6),79 [{text: "hello world"}],80 "The close tag is missing.");81});82test('Event test', function() {83 var eventTestString = "<on click=' event1' hoverin='event2 ' hoverout = 'event3'>hello world</on>";84 deepEqual(parser.parse(eventTestString),85 [{text: "hello world", style: {86 event: {87 click : "event1"88 }}}], "Happy path 1");89 var eventTestStringFail1 = "<on click=' event1' hoverin'event2 ' hoverout=event3>hello world</on>";90 deepEqual(parser.parse(eventTestStringFail1),91 [{text: "hello world", style: {92 event: {93 click : "event1",94 }}}], "Fail path 1");95 var eventTestStringFail2 = "<size=20 click=' event1' hoverin=event2 hoverout:event3>hello world</on>";96 deepEqual(parser.parse(eventTestStringFail2),97 [{text: "hello world", style: {98 size: 20,99 event: {100 click : "event1",101 }}}], "Fail path 2");102 var eventTestStringFail3 = "<size=20 click=event1 hoverin='event2' hoverout:event3>hello world</on>";103 deepEqual(parser.parse(eventTestStringFail3),104 [{text: "hello world", style: {105 size: 20,106 event: {107 }}}], "Fail path 3");108 var eventTestString2 = "<color=#0xff0000 click=\"event1\">Super weapon</color>";109 deepEqual(parser.parse(eventTestString2),110 [{text: "Super weapon", style: {111 color: "#0xff0000",112 event: {113 click : "event1",114 }115 }}], "Color with event");116 var eventTestString3 = "<size=20 click='event1' hoverin='event2'>hello world</>";117 deepEqual(parser.parse(eventTestString3),118 [{text: "hello world",119 style: {120 size: 20,121 event: {122 click : "event1",123 }124 }}], "Size with event");125 var eventTestString4 = "<sie=20 click='event1' hoverin='event2'>hello world</>";126 deepEqual(parser.parse(eventTestString4),127 [{text: "hello world",128 style: {}129 }], "Failed path: Size with event");130 var invalidEventTestString4 = "<size=20 click='event1\">hello world</>";131 deepEqual(parser.parse(invalidEventTestString4),132 [{text: "hello world",133 style: {size: 20,134 event: {}}135 }], "Failed path: event name quote not match.");136 var invalidEventTestString5 = "<size=20 click=\"event1'>hello world</>";137 deepEqual(parser.parse(invalidEventTestString5),138 [{text: "hello world",139 style: {size: 20,140 event: {}}141 }], "Failed path: event name quote not match.");142});143test('Test special symbol escape', function() {144 var testLessThan = "<size=20>hello&lt;world</size>";145 deepEqual(parser.parse(testLessThan),146 [ {text: "hello<world",147 style: {148 size: 20149 }150 }],151 "The &lt; symbol should be correctly escaped.");152 var testGreatThan = "<on click='event1'> hello&gt;world</on>";153 deepEqual(parser.parse(testGreatThan),154 [{text: " hello>world",155 style: {156 event: {157 click: 'event1'158 }159 }}],160 "The &gt; symbol should be correctly escaped.");161 var testAmp = "<color=#0xff00>hello&amp;world</>";162 deepEqual(parser.parse(testAmp),163 [{text: "hello&world",164 style: {165 color: "#0xff00"166 }}],167 "The amp symbol should be correctly escaped.");168 var testQuot = "<on>hello&quot;world</on>";169 deepEqual(parser.parse(testQuot),170 [{text: "hello\"world",171 style: {}}],172 "The quot symbol should be correctly escaped.");173 var testApos = "<color=#0xffee>Hi, <size=20>hello&apos;world</s></c>";174 deepEqual(parser.parse(testApos),175 [{text: "Hi, ",176 style: {177 color: "#0xffee"178 }},179 {text: "hello'world",180 style: {181 color: "#0xffee",182 size: 20183 }}],184 "The apos symbol should be correctly escaped.");185});186test('Integrate test', function() {187 var eventTestString = "hello <b>world</b>, <color=#0xff0000> Ni hao </color>";188 deepEqual(parser.parse(eventTestString),189 [{text: "hello "}, {text: "world", style: {bold: true}},190 {text: ", "},191 {text: " Ni hao ", style : {color: "#0xff0000"}}], "Happy path 1");192 var moreComplexString = "<size=20>大小<size=10>不一</size></size>,<color=#0xffeeaa>颜色</c><color=#0xffaaee>不同</c><on click='event1'>可点击</on>";193 deepEqual(parser.parse(moreComplexString),194 [{text: "大小", style: {size: 20}}, {text: "不一", style: {size: 10}}, {text:","},195 {text: "颜色", style: {color: "#0xffeeaa"}}, {text: "不同", style: {color: "#0xffaaee"}},196 {text: "可点击", style: {event: {click: 'event1'}}}], "more complex test");197});198test('bold/italic/underline test', function () {199 var stringWithBold = "<b></i><b>hello \n world</b>";200 deepEqual(parser.parse(stringWithBold),201 [{text: "hello \n world", style: {bold: true}}], "bold test");202 var stringWithItalic = "<i>hello world</i>";203 deepEqual(parser.parse(stringWithItalic),204 [{text: "hello world", style: {italic: true}}], "italic test");205 var stringWithUnderline = "<u>hello world</u>";206 deepEqual(parser.parse(stringWithUnderline),207 [{text: "hello world", style: {underline: true}}], "underline test");208});209test('test br tag', function () {210 var newlineTest = "<br/>";211 deepEqual(parser.parse(newlineTest),212 [{text: "", style: {newline: true}},], "newline element test");213 var newlineTest2 = "hello <b>a< br /></b> world";214 deepEqual(parser.parse(newlineTest2),215 [{text: "hello "},216 {text: "a", style: {bold: true}},217 {text: "", style: {newline: true}},218 {text: " world"}219 ], "newline element test");220 var newlineTest3 = "< br />";221 deepEqual(parser.parse(newlineTest3),222 [{text: "", style: {newline: true}},], "newline element test");223 var newlineTest4 = "<br></br>";224 deepEqual(parser.parse(newlineTest4),225 [], "newline element test");226 var newlineTest5 = "hello <b>a<br></></b> world";227 deepEqual(parser.parse(newlineTest5),228 [{text: "hello "},229 {text: "a", style: {bold: true}},230 {text: " world"}231 ], "newline element test");232 var newlineTest6 = "hello <b>a<br /><br/ ></b> world";233 deepEqual(parser.parse(newlineTest6),234 [{text: "hello "},235 {text: "a", style: {bold: true}},236 {text: "", style: {newline: true}},237 {text: "", style: {newline: true}},238 {text: " world"}239 ], "newline element test");240 var newlineTest7 = "hello <b>a</b><br /><br/ >world";241 deepEqual(parser.parse(newlineTest7),242 [{text: "hello "},243 {text: "a", style: {bold: true}},244 {text: "", style: {newline: true}},245 {text: "", style: {newline: true}},246 {text: "world"}247 ], "newline element test");248});249test('test image tag', function () {250 var imageTest1 = "<img src='weapon' />";251 deepEqual(parser.parse(imageTest1),252 [253 {text: "",254 style: {isImage: true, src: "weapon"}}255 ], "image element test 1");256 var imageTest2 = '<img src = "weapon"/>';257 deepEqual(parser.parse(imageTest2),258 [259 {text: "", style: {isImage: true, src: "weapon"}}260 ], "image element test 2");261 var imageTest3 = "hello, <b>world<img src='nihao' /></>";262 deepEqual(parser.parse(imageTest3),263 [264 {text: "hello, "},265 {text: "world", style : {bold: true}},266 {text: "", style: {isImage: true, src: "nihao"}}267 ], "image element test");268 var imageTest4 = "hello, <b>world<img src=nihao / ></>";269 deepEqual(parser.parse(imageTest4),270 [271 {text: "hello, "},272 {text: "world", style : {bold: true}},273 ], "image element test");274 var imageTest5 = "hello, <b>world<on click='handler'><img src=nihao / ></on></b>";275 deepEqual(parser.parse(imageTest5),276 [277 {text: "hello, "},278 {text: "world", style : {bold: true}},279 ], "image element event test");280 var imageTest6 = "hello, <b>world<img src='head' click='handler' /></b>";281 deepEqual(parser.parse(imageTest6),282 [283 {text: "hello, "},284 {text: "world", style : {bold: true}},285 {text: "", style: {isImage: true, src: "head",286 event: {click: "handler"}}}287 ], "image element event test");288 var invalidImageTest1 = "<img src='hello'></img>";289 deepEqual(parser.parse(invalidImageTest1),290 [], "image element invalid test");291 var invalidImageTest2 = "<img src='world'>";292 deepEqual(parser.parse(invalidImageTest2),293 [], "image element invalid test");294 var invalidImageTest3 = "<image src='world' />";295 deepEqual(parser.parse(invalidImageTest3),296 [], "image element invalid test");297 var nestedImageTest4 = "<b><u><img src='world' click='handler' /></b></u>";298 deepEqual(parser.parse(nestedImageTest4),299 [{text: "", style: {isImage: true, src: 'world',300 event: {click: 'handler'}}}], "image element invalid test");301});302test('test outline tag', function () {303 var outlineTest1 = "<outline color = #0f00ff width=2 >hello</outline>";304 deepEqual(parser.parse(outlineTest1),305 [306 {text: "hello",307 style: { outline: {308 color: "#0f00ff",309 width: 2310 }}}311 ], "outline element test 1");312 var outlineTest2 = '<outline color= #0f00ff>hello</outline>';313 deepEqual(parser.parse(outlineTest2),314 [315 {text: "hello", style: {316 outline: {317 color: "#0f00ff",318 width: 1319 }320 }}321 ], "outline element test 2");322 var outlineTest3 = '<outline width = 4>hello</outline>';323 deepEqual(parser.parse(outlineTest3),324 [325 {text: "hello", style: {326 outline: {327 color: "#ffffff",328 width: 4329 }330 }}331 ], "outline element test 3");332 var outlineTest4 = '<outline >hello</outline>';333 deepEqual(parser.parse(outlineTest4),334 [335 {text: "hello", style: {336 outline: {337 color: "#ffffff",338 width: 1339 }340 }}341 ], "outline element test 4");342 var outlineTest5 = "<outline click= 'clickme' width =2 color=#0f00ff>hello</outline>";343 deepEqual(parser.parse(outlineTest5),344 [345 {text: "hello",346 style: {347 outline: {348 color: "#0f00ff",349 width: 2350 },351 event: {352 click: "clickme"353 }354 }}355 ], "outline element test 5");356 var outlineTest6 = "<outline width =2 color=#0f00ff click='clickme'>hello</outline>";357 deepEqual(parser.parse(outlineTest6),358 [359 {text: "hello",360 style: {361 outline: {362 color: "#0f00ff",363 width: 2364 },365 event: {366 click: "clickme"367 }368 }}369 ], "outline element test 6");370 var outlineTest7 = "<outline width =2 color=#0f00ff><on click='clickme'>hello</on></outline>";371 deepEqual(parser.parse(outlineTest7),372 [373 {text: "hello",374 style: {375 outline: {376 color: "#0f00ff",377 width: 2378 },379 event: {380 click: "clickme"381 }382 }}383 ], "outline element test 7");384 var outlineTest8 = "<b><outline width =2 color=#0f00ff><on click='clickme'><u>hello</u></on></outline></b>";385 deepEqual(parser.parse(outlineTest8),386 [387 {text: "hello",388 style: {389 bold: true,390 underline: true,391 outline: {392 color: "#0f00ff",393 width: 2394 },395 event: {396 click: "clickme"397 }398 }}399 ], "outline element test 8");400 var invalidOutlineTest1 = "<outline width=2 color #0f00ff click='clickme'>hello</outline>";401 deepEqual(parser.parse(invalidOutlineTest1),402 [403 {text: "hello",404 style: {405 outline: {406 color: "#ffffff",407 width: 2408 },409 event: {410 click: "clickme"411 }412 }}413 ], "invalid outline element test 1");414 var invalidOutlineTest2 = "<outline width 2 color #0f00ff click 'clickme'>hello</outline>";415 deepEqual(parser.parse(invalidOutlineTest2),416 [417 {text: "hello",418 style: {419 outline: {420 color: "#ffffff",421 width: 1422 }423 }}424 ], "invalid outline element test 2");425 var invalidOutlineTest3 = "<outilne width 2 color #0f00ff click 'clickme'>hello</outline>";426 deepEqual(parser.parse(invalidOutlineTest3),427 [428 {text: "hello",429 style: {}}430 ], "invalid outline element test 3");...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1/* globals suite test */2var assert = require('assert')3var flat = require('../index')4var flatten = flat.flatten5var unflatten = flat.unflatten6var primitives = {7 String: 'good morning',8 Number: 1234.99,9 Boolean: true,10 Date: new Date(),11 null: null,12 undefined: undefined13}14suite('Flatten Primitives', function () {15 Object.keys(primitives).forEach(function (key) {16 var value = primitives[key]17 test(key, function () {18 assert.deepEqual(flatten({19 hello: {20 world: value21 }22 }), {23 'hello.world': value24 })25 })26 })27})28suite('Unflatten Primitives', function () {29 Object.keys(primitives).forEach(function (key) {30 var value = primitives[key]31 test(key, function () {32 assert.deepEqual(unflatten({33 'hello.world': value34 }), {35 hello: {36 world: value37 }38 })39 })40 })41})42suite('Flatten', function () {43 test('Nested once', function () {44 assert.deepEqual(flatten({45 hello: {46 world: 'good morning'47 }48 }), {49 'hello.world': 'good morning'50 })51 })52 test('Nested twice', function () {53 assert.deepEqual(flatten({54 hello: {55 world: {56 again: 'good morning'57 }58 }59 }), {60 'hello.world.again': 'good morning'61 })62 })63 test('Multiple Keys', function () {64 assert.deepEqual(flatten({65 hello: {66 lorem: {67 ipsum: 'again',68 dolor: 'sit'69 }70 },71 world: {72 lorem: {73 ipsum: 'again',74 dolor: 'sit'75 }76 }77 }), {78 'hello.lorem.ipsum': 'again',79 'hello.lorem.dolor': 'sit',80 'world.lorem.ipsum': 'again',81 'world.lorem.dolor': 'sit'82 })83 })84 test('Custom Delimiter', function () {85 assert.deepEqual(flatten({86 hello: {87 world: {88 again: 'good morning'89 }90 }91 }, {92 delimiter: ':'93 }), {94 'hello:world:again': 'good morning'95 })96 })97 test('Empty Objects', function () {98 assert.deepEqual(flatten({99 hello: {100 empty: {101 nested: { }102 }103 }104 }), {105 'hello.empty.nested': { }106 })107 })108 if (typeof Buffer !== 'undefined') {109 test('Buffer', function () {110 assert.deepEqual(flatten({111 hello: {112 empty: {113 nested: Buffer.from('test')114 }115 }116 }), {117 'hello.empty.nested': Buffer.from('test')118 })119 })120 }121 if (typeof Uint8Array !== 'undefined') {122 test('typed arrays', function () {123 assert.deepEqual(flatten({124 hello: {125 empty: {126 nested: new Uint8Array([1, 2, 3, 4])127 }128 }129 }), {130 'hello.empty.nested': new Uint8Array([1, 2, 3, 4])131 })132 })133 }134 test('Custom Depth', function () {135 assert.deepEqual(flatten({136 hello: {137 world: {138 again: 'good morning'139 }140 },141 lorem: {142 ipsum: {143 dolor: 'good evening'144 }145 }146 }, {147 maxDepth: 2148 }), {149 'hello.world': {150 again: 'good morning'151 },152 'lorem.ipsum': {153 dolor: 'good evening'154 }155 })156 })157 test('Should keep number in the left when object', function () {158 assert.deepEqual(flatten({159 hello: {160 '0200': 'world',161 '0500': 'darkness my old friend'162 }163 }), {164 'hello.0200': 'world',165 'hello.0500': 'darkness my old friend'166 })167 })168})169suite('Unflatten', function () {170 test('Nested once', function () {171 assert.deepEqual({172 hello: {173 world: 'good morning'174 }175 }, unflatten({176 'hello.world': 'good morning'177 }))178 })179 test('Nested twice', function () {180 assert.deepEqual({181 hello: {182 world: {183 again: 'good morning'184 }185 }186 }, unflatten({187 'hello.world.again': 'good morning'188 }))189 })190 test('Multiple Keys', function () {191 assert.deepEqual({192 hello: {193 lorem: {194 ipsum: 'again',195 dolor: 'sit'196 }197 },198 world: {199 greet: 'hello',200 lorem: {201 ipsum: 'again',202 dolor: 'sit'203 }204 }205 }, unflatten({206 'hello.lorem.ipsum': 'again',207 'hello.lorem.dolor': 'sit',208 'world.lorem.ipsum': 'again',209 'world.lorem.dolor': 'sit',210 'world': {greet: 'hello'}211 }))212 })213 test('nested objects do not clobber each other when a.b inserted before a', function () {214 var x = {}215 x['foo.bar'] = {t: 123}216 x['foo'] = {p: 333}217 assert.deepEqual(unflatten(x), {218 foo: {219 bar: {220 t: 123221 },222 p: 333223 }224 })225 })226 test('Custom Delimiter', function () {227 assert.deepEqual({228 hello: {229 world: {230 again: 'good morning'231 }232 }233 }, unflatten({234 'hello world again': 'good morning'235 }, {236 delimiter: ' '237 }))238 })239 test('Overwrite', function () {240 assert.deepEqual({241 travis: {242 build: {243 dir: '/home/travis/build/kvz/environmental'244 }245 }246 }, unflatten({247 travis: 'true',248 travis_build_dir: '/home/travis/build/kvz/environmental'249 }, {250 delimiter: '_',251 overwrite: true252 }))253 })254 test('Messy', function () {255 assert.deepEqual({256 hello: { world: 'again' },257 lorem: { ipsum: 'another' },258 good: {259 morning: {260 hash: {261 key: { nested: {262 deep: { and: { even: {263 deeper: { still: 'hello' }264 } } }265 } }266 },267 again: { testing: { 'this': 'out' } }268 }269 }270 }, unflatten({271 'hello.world': 'again',272 'lorem.ipsum': 'another',273 'good.morning': {274 'hash.key': {275 'nested.deep': {276 'and.even.deeper.still': 'hello'277 }278 }279 },280 'good.morning.again': {281 'testing.this': 'out'282 }283 }))284 })285 suite('Overwrite + non-object values in key positions', function () {286 test('non-object keys + overwrite should be overwritten', function () {287 assert.deepEqual(flat.unflatten({ a: null, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } })288 assert.deepEqual(flat.unflatten({ a: 0, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } })289 assert.deepEqual(flat.unflatten({ a: 1, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } })290 assert.deepEqual(flat.unflatten({ a: '', 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } })291 })292 test('overwrite value should not affect undefined keys', function () {293 assert.deepEqual(flat.unflatten({ a: undefined, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } })294 assert.deepEqual(flat.unflatten({ a: undefined, 'a.b': 'c' }, {overwrite: false}), { a: { b: 'c' } })295 })296 test('if no overwrite, should ignore nested values under non-object key', function () {297 assert.deepEqual(flat.unflatten({ a: null, 'a.b': 'c' }), { a: null })298 assert.deepEqual(flat.unflatten({ a: 0, 'a.b': 'c' }), { a: 0 })299 assert.deepEqual(flat.unflatten({ a: 1, 'a.b': 'c' }), { a: 1 })300 assert.deepEqual(flat.unflatten({ a: '', 'a.b': 'c' }), { a: '' })301 })302 })303 suite('.safe', function () {304 test('Should protect arrays when true', function () {305 assert.deepEqual(flatten({306 hello: [307 { world: { again: 'foo' } },308 { lorem: 'ipsum' }309 ],310 another: {311 nested: [{ array: { too: 'deep' } }]312 },313 lorem: {314 ipsum: 'whoop'315 }316 }, {317 safe: true318 }), {319 hello: [320 { world: { again: 'foo' } },321 { lorem: 'ipsum' }322 ],323 'lorem.ipsum': 'whoop',324 'another.nested': [{ array: { too: 'deep' } }]325 })326 })327 test('Should not protect arrays when false', function () {328 assert.deepEqual(flatten({329 hello: [330 { world: { again: 'foo' } },331 { lorem: 'ipsum' }332 ]333 }, {334 safe: false335 }), {336 'hello.0.world.again': 'foo',337 'hello.1.lorem': 'ipsum'338 })339 })340 })341 suite('.object', function () {342 test('Should create object instead of array when true', function () {343 var unflattened = unflatten({344 'hello.you.0': 'ipsum',345 'hello.you.1': 'lorem',346 'hello.other.world': 'foo'347 }, {348 object: true349 })350 assert.deepEqual({351 hello: {352 you: {353 0: 'ipsum',354 1: 'lorem'355 },356 other: { world: 'foo' }357 }358 }, unflattened)359 assert(!Array.isArray(unflattened.hello.you))360 })361 test('Should create object instead of array when nested', function () {362 var unflattened = unflatten({363 'hello': {364 'you.0': 'ipsum',365 'you.1': 'lorem',366 'other.world': 'foo'367 }368 }, {369 object: true370 })371 assert.deepEqual({372 hello: {373 you: {374 0: 'ipsum',375 1: 'lorem'376 },377 other: { world: 'foo' }378 }379 }, unflattened)380 assert(!Array.isArray(unflattened.hello.you))381 })382 test('Should keep the zero in the left when object is true', function () {383 var unflattened = unflatten({384 'hello.0200': 'world',385 'hello.0500': 'darkness my old friend'386 }, {387 object: true388 })389 assert.deepEqual({390 hello: {391 '0200': 'world',392 '0500': 'darkness my old friend'393 }394 }, unflattened)395 })396 test('Should not create object when false', function () {397 var unflattened = unflatten({398 'hello.you.0': 'ipsum',399 'hello.you.1': 'lorem',400 'hello.other.world': 'foo'401 }, {402 object: false403 })404 assert.deepEqual({405 hello: {406 you: ['ipsum', 'lorem'],407 other: { world: 'foo' }408 }409 }, unflattened)410 assert(Array.isArray(unflattened.hello.you))411 })412 })413 if (typeof Buffer !== 'undefined') {414 test('Buffer', function () {415 assert.deepEqual(unflatten({416 'hello.empty.nested': Buffer.from('test')417 }), {418 hello: {419 empty: {420 nested: Buffer.from('test')421 }422 }423 })424 })425 }426 if (typeof Uint8Array !== 'undefined') {427 test('typed arrays', function () {428 assert.deepEqual(unflatten({429 'hello.empty.nested': new Uint8Array([1, 2, 3, 4])430 }), {431 hello: {432 empty: {433 nested: new Uint8Array([1, 2, 3, 4])434 }435 }436 })437 })438 }439})440suite('Arrays', function () {441 test('Should be able to flatten arrays properly', function () {442 assert.deepEqual({443 'a.0': 'foo',444 'a.1': 'bar'445 }, flatten({446 a: ['foo', 'bar']447 }))448 })449 test('Should be able to revert and reverse array serialization via unflatten', function () {450 assert.deepEqual({451 a: ['foo', 'bar']452 }, unflatten({453 'a.0': 'foo',454 'a.1': 'bar'455 }))456 })457 test('Array typed objects should be restored by unflatten', function () {458 assert.equal(459 Object.prototype.toString.call(['foo', 'bar'])460 , Object.prototype.toString.call(unflatten({461 'a.0': 'foo',462 'a.1': 'bar'463 }).a)464 )465 })466 test('Do not include keys with numbers inside them', function () {467 assert.deepEqual(unflatten({468 '1key.2_key': 'ok'469 }), {470 '1key': {471 '2_key': 'ok'472 }473 })474 })...

Full Screen

Full Screen

helloworlddialog.js

Source:helloworlddialog.js Github

copy

Full Screen

1// Copyright 2008 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview An example of how to write a dialog to be opened by a plugin.16 *17 */18goog.provide('goog.demos.editor.HelloWorldDialog');19goog.provide('goog.demos.editor.HelloWorldDialog.OkEvent');20goog.require('goog.dom.TagName');21goog.require('goog.events.Event');22goog.require('goog.string');23goog.require('goog.ui.editor.AbstractDialog');24goog.require('goog.ui.editor.AbstractDialog.Builder');25goog.require('goog.ui.editor.AbstractDialog.EventType');26// *** Public interface ***************************************************** //27/**28 * Creates a dialog to let the user enter a customized hello world message.29 * @param {goog.dom.DomHelper} domHelper DomHelper to be used to create the30 * dialog's dom structure.31 * @constructor32 * @extends {goog.ui.editor.AbstractDialog}33 */34goog.demos.editor.HelloWorldDialog = function(domHelper) {35 goog.ui.editor.AbstractDialog.call(this, domHelper);36};37goog.inherits(goog.demos.editor.HelloWorldDialog,38 goog.ui.editor.AbstractDialog);39// *** Event **************************************************************** //40/**41 * OK event object for the hello world dialog.42 * @param {string} message Customized hello world message chosen by the user.43 * @constructor44 * @extends {goog.events.Event}45 */46goog.demos.editor.HelloWorldDialog.OkEvent = function(message) {47 this.message = message;48};49goog.inherits(goog.demos.editor.HelloWorldDialog.OkEvent, goog.events.Event);50/**51 * Event type.52 * @type {goog.ui.editor.AbstractDialog.EventType}53 * @override54 */55goog.demos.editor.HelloWorldDialog.OkEvent.prototype.type =56 goog.ui.editor.AbstractDialog.EventType.OK;57/**58 * Customized hello world message chosen by the user.59 * @type {string}60 */61goog.demos.editor.HelloWorldDialog.OkEvent.prototype.message;62// *** Protected interface ************************************************** //63/** @override */64goog.demos.editor.HelloWorldDialog.prototype.createDialogControl = function() {65 var builder = new goog.ui.editor.AbstractDialog.Builder(this);66 /** @desc Title of the hello world dialog. */67 var MSG_HELLO_WORLD_DIALOG_TITLE = goog.getMsg('Add a Hello World message');68 builder.setTitle(MSG_HELLO_WORLD_DIALOG_TITLE).69 setContent(this.createContent_());70 return builder.build();71};72/**73 * Creates and returns the event object to be used when dispatching the OK74 * event to listeners, or returns null to prevent the dialog from closing.75 * @param {goog.events.Event} e The event object dispatched by the wrapped76 * dialog.77 * @return {goog.demos.editor.HelloWorldDialog.OkEvent} The event object to be78 * used when dispatching the OK event to listeners.79 * @protected80 * @override81 */82goog.demos.editor.HelloWorldDialog.prototype.createOkEvent = function(e) {83 var message = this.getMessage_();84 if (message &&85 goog.demos.editor.HelloWorldDialog.isValidHelloWorld_(message)) {86 return new goog.demos.editor.HelloWorldDialog.OkEvent(message);87 } else {88 /** @desc Error message telling the user why their message was rejected. */89 var MSG_HELLO_WORLD_DIALOG_ERROR =90 goog.getMsg('Your message must contain the words "hello" and "world".');91 this.dom.getWindow().alert(MSG_HELLO_WORLD_DIALOG_ERROR);92 return null; // Prevents the dialog from closing.93 }94};95// *** Private implementation *********************************************** //96/**97 * Input element where the user will type their hello world message.98 * @type {Element}99 * @private100 */101goog.demos.editor.HelloWorldDialog.prototype.input_;102/**103 * Creates the DOM structure that makes up the dialog's content area.104 * @return {Element} The DOM structure that makes up the dialog's content area.105 * @private106 */107goog.demos.editor.HelloWorldDialog.prototype.createContent_ = function() {108 /** @desc Sample hello world message to prepopulate the dialog with. */109 var MSG_HELLO_WORLD_DIALOG_SAMPLE = goog.getMsg('Hello, world!');110 this.input_ = this.dom.createDom(goog.dom.TagName.INPUT,111 {size: 25, value: MSG_HELLO_WORLD_DIALOG_SAMPLE});112 /** @desc Prompt telling the user to enter a hello world message. */113 var MSG_HELLO_WORLD_DIALOG_PROMPT =114 goog.getMsg('Enter your Hello World message');115 return this.dom.createDom(goog.dom.TagName.DIV,116 null,117 [MSG_HELLO_WORLD_DIALOG_PROMPT, this.input_]);118};119/**120 * Returns the hello world message currently typed into the dialog's input.121 * @return {?string} The hello world message currently typed into the dialog's122 * input, or null if called before the input is created.123 * @private124 */125goog.demos.editor.HelloWorldDialog.prototype.getMessage_ = function() {126 return this.input_ && this.input_.value;127};128/**129 * Returns whether or not the given message contains the strings "hello" and130 * "world". Case-insensitive and order doesn't matter.131 * @param {string} message The message to be checked.132 * @return {boolean} Whether or not the given message contains the strings133 * "hello" and "world".134 * @private135 */136goog.demos.editor.HelloWorldDialog.isValidHelloWorld_ = function(message) {137 message = message.toLowerCase();138 return goog.string.contains(message, 'hello') &&139 goog.string.contains(message, 'world');...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/**2 Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.3 Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at4 http://aws.amazon.com/apache2.0/5 or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.6*/7/**8 * This simple sample has no external dependencies or session management, and shows the most basic9 * example of how to create a Lambda function for handling Alexa Skill requests.10 *11 * Examples:12 * One-shot model:13 * User: "Alexa, tell Hello World to say hello"14 * Alexa: "Hello World!"15 */16/**17 * App ID for the skill18 */19var APP_ID = "amzn1.ask.skill.c126aa6d-8be7-4470-8fe5-ce16cc4832b9";20/**21 * The AlexaSkill prototype and helper functions22 */23var AlexaSkill = require('./AlexaSkill');24var auth = require('./auth');25var graph = require('./graph');26/**27 * HelloWorld is a child of AlexaSkill.28 * To read more about inheritance in JavaScript, see the link below.29 *30 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript#Inheritance31 */32var HelloWorld = function () {33 AlexaSkill.call(this, APP_ID);34};35// Extend AlexaSkill36HelloWorld.prototype = Object.create(AlexaSkill.prototype);37HelloWorld.prototype.constructor = HelloWorld;38HelloWorld.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) {39 console.log("HelloWorld onSessionStarted requestId: " + sessionStartedRequest.requestId40 + ", sessionId: " + session.sessionId);41 // any initialization logic goes here42};43HelloWorld.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {44 console.log("HelloWorld onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId);45 var speechOutput = "Welcome to the Alexa Skills Kit, you can say hello";46 var repromptText = "You can say hello";47 response.ask(speechOutput, repromptText);48};49HelloWorld.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) {50 console.log("HelloWorld onSessionEnded requestId: " + sessionEndedRequest.requestId51 + ", sessionId: " + session.sessionId);52 // any cleanup logic goes here53};54function CreateCalendarEvent(intent, session, response) {55}56HelloWorld.prototype.intentHandlers = {57 // register custom intent handlers58 "HelloWorldIntent": function (intent, session, response) {59 response.tellWithCard("Hello World!", "Hello World", "Hello World!");60 },61 "AddCalendarItemIntent": function (intent, session, response) {62 // Get an access token for the app.63 auth.getAccessToken().then(function (token) {64 // Get all of the users in the tenant.65 graph.getUsers(token)66 .then(function (users) {67 // Create an event on each user's calendar.68 var result = graph.createEvent(token, users, response);69 }, function (error) {70 var errorMsg = '>>> Error getting users: ' + error;71 console.error(errorMsg);72 response.tellWithCard("Error:" + errorMsg, "Hello World", "Hello World!"); 73 });74 }, function (error) {75 var errorMsg = '>>> Error getting access token: ' + error;76 console.error(errorMsg);77 response.tellWithCard("Error:" + errorMsg, "Hello World", "Hello World!"); 78 });79 },80 "AddListItemIntent": function (intent, session, response) {81 // Get an access token for the app.82 auth.getAccessToken().then(function (token) {83 var result = graph.createItem(84 token, 85 function(reqError) {86 if(reqError) {87 response.tellWithCard("Error:" + reqError, "Hello World", "Hello World!");88 }89 else {90 response.tellWithCard("List Item Created", "Hello World", "Hello World!");91 }92 });93 }, function (error) {94 var errorMsg = '>>> Error getting access token: ' + error;95 console.error(errorMsg);96 response.tellWithCard("Error:" + errorMsg, "Hello World", "Hello World!"); 97 });98 },99 "AMAZON.HelpIntent": function (intent, session, response) {100 response.ask("You can say hello to me!", "You can say hello to me!");101 }102};103// Create the handler that responds to the Alexa Request.104exports.handler = function (event, context) {105 // Create an instance of the HelloWorld skill.106 var helloWorld = new HelloWorld();107 helloWorld.execute(event, context);...

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 Kiwi 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