michael@0: (function() { michael@0: var mode = CodeMirror.getMode({indentUnit: 2}, "javascript"); michael@0: function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } michael@0: michael@0: MT("locals", michael@0: "[keyword function] [variable foo]([def a], [def b]) { [keyword var] [def c] [operator =] [number 10]; [keyword return] [variable-2 a] [operator +] [variable-2 c] [operator +] [variable d]; }"); michael@0: michael@0: MT("comma-and-binop", michael@0: "[keyword function](){ [keyword var] [def x] [operator =] [number 1] [operator +] [number 2], [def y]; }"); michael@0: michael@0: MT("destructuring", michael@0: "([keyword function]([def a], [[[def b], [def c] ]]) {", michael@0: " [keyword let] {[def d], [property foo]: [def c][operator =][number 10], [def x]} [operator =] [variable foo]([variable-2 a]);", michael@0: " [[[variable-2 c], [variable y] ]] [operator =] [variable-2 c];", michael@0: "})();"); michael@0: michael@0: MT("class", michael@0: "[keyword class] [variable Point] [keyword extends] [variable SuperThing] {", michael@0: " [[ [string-2 /expr/] ]]: [number 24],", michael@0: " [property constructor]([def x], [def y]) {", michael@0: " [keyword super]([string 'something']);", michael@0: " [keyword this].[property x] [operator =] [variable-2 x];", michael@0: " }", michael@0: "}"); michael@0: michael@0: MT("module", michael@0: "[keyword module] [string 'foo'] {", michael@0: " [keyword export] [keyword let] [def x] [operator =] [number 42];", michael@0: " [keyword export] [keyword *] [keyword from] [string 'somewhere'];", michael@0: "}"); michael@0: michael@0: MT("import", michael@0: "[keyword function] [variable foo]() {", michael@0: " [keyword import] [def $] [keyword from] [string 'jquery'];", michael@0: " [keyword module] [def crypto] [keyword from] [string 'crypto'];", michael@0: " [keyword import] { [def encrypt], [def decrypt] } [keyword from] [string 'crypto'];", michael@0: "}"); michael@0: michael@0: MT("const", michael@0: "[keyword function] [variable f]() {", michael@0: " [keyword const] [[ [def a], [def b] ]] [operator =] [[ [number 1], [number 2] ]];", michael@0: "}"); michael@0: michael@0: MT("for/of", michael@0: "[keyword for]([keyword let] [variable of] [keyword of] [variable something]) {}"); michael@0: michael@0: MT("generator", michael@0: "[keyword function*] [variable repeat]([def n]) {", michael@0: " [keyword for]([keyword var] [def i] [operator =] [number 0]; [variable-2 i] [operator <] [variable-2 n]; [operator ++][variable-2 i])", michael@0: " [keyword yield] [variable-2 i];", michael@0: "}"); michael@0: michael@0: MT("fatArrow", michael@0: "[variable array].[property filter]([def a] [operator =>] [variable-2 a] [operator +] [number 1]);", michael@0: "[variable a];", // No longer in scope michael@0: "[keyword let] [variable f] [operator =] ([[ [def a], [def b] ]], [def c]) [operator =>] [variable-2 a] [operator +] [variable-2 c];", michael@0: "[variable c];"); michael@0: michael@0: MT("spread", michael@0: "[keyword function] [variable f]([def a], [meta ...][def b]) {", michael@0: " [variable something]([variable-2 a], [meta ...][variable-2 b]);", michael@0: "}"); michael@0: michael@0: MT("comprehension", michael@0: "[keyword function] [variable f]() {", michael@0: " [[([variable x] [operator +] [number 1]) [keyword for] ([keyword var] [def x] [keyword in] [variable y]) [keyword if] [variable pred]([variable-2 x]) ]];", michael@0: " ([variable u] [keyword for] ([keyword var] [def u] [keyword of] [variable generateValues]()) [keyword if] ([variable-2 u].[property color] [operator ===] [string 'blue']));", michael@0: "}"); michael@0: michael@0: MT("quasi", michael@0: "[variable re][string-2 `fofdlakj${][variable x] [operator +] ([variable re][string-2 `foo`]) [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]"); michael@0: michael@0: MT("indent_statement", michael@0: "[keyword var] [variable x] [operator =] [number 10]", michael@0: "[variable x] [operator +=] [variable y] [operator +]", michael@0: " [atom Infinity]", michael@0: "[keyword debugger];"); michael@0: michael@0: MT("indent_if", michael@0: "[keyword if] ([number 1])", michael@0: " [keyword break];", michael@0: "[keyword else] [keyword if] ([number 2])", michael@0: " [keyword continue];", michael@0: "[keyword else]", michael@0: " [number 10];", michael@0: "[keyword if] ([number 1]) {", michael@0: " [keyword break];", michael@0: "} [keyword else] [keyword if] ([number 2]) {", michael@0: " [keyword continue];", michael@0: "} [keyword else] {", michael@0: " [number 10];", michael@0: "}"); michael@0: michael@0: MT("indent_for", michael@0: "[keyword for] ([keyword var] [variable i] [operator =] [number 0];", michael@0: " [variable i] [operator <] [number 100];", michael@0: " [variable i][operator ++])", michael@0: " [variable doSomething]([variable i]);", michael@0: "[keyword debugger];"); michael@0: michael@0: MT("indent_c_style", michael@0: "[keyword function] [variable foo]()", michael@0: "{", michael@0: " [keyword debugger];", michael@0: "}"); michael@0: michael@0: MT("multilinestring", michael@0: "[keyword var] [variable x] [operator =] [string 'foo\\]", michael@0: "[string bar'];"); michael@0: michael@0: MT("scary_regexp", michael@0: "[string-2 /foo[[/]]bar/];"); michael@0: michael@0: var jsonld_mode = CodeMirror.getMode( michael@0: {indentUnit: 2}, michael@0: {name: "javascript", jsonld: true} michael@0: ); michael@0: function LD(name) { michael@0: test.mode(name, jsonld_mode, Array.prototype.slice.call(arguments, 1)); michael@0: } michael@0: michael@0: LD("json_ld_keywords", michael@0: '{', michael@0: ' [meta "@context"]: {', michael@0: ' [meta "@base"]: [string "http://example.com"],', michael@0: ' [meta "@vocab"]: [string "http://xmlns.com/foaf/0.1/"],', michael@0: ' [property "likesFlavor"]: {', michael@0: ' [meta "@container"]: [meta "@list"]', michael@0: ' [meta "@reverse"]: [string "@beFavoriteOf"]', michael@0: ' },', michael@0: ' [property "nick"]: { [meta "@container"]: [meta "@set"] },', michael@0: ' [property "nick"]: { [meta "@container"]: [meta "@index"] }', michael@0: ' },', michael@0: ' [meta "@graph"]: [[ {', michael@0: ' [meta "@id"]: [string "http://dbpedia.org/resource/John_Lennon"],', michael@0: ' [property "name"]: [string "John Lennon"],', michael@0: ' [property "modified"]: {', michael@0: ' [meta "@value"]: [string "2010-05-29T14:17:39+02:00"],', michael@0: ' [meta "@type"]: [string "http://www.w3.org/2001/XMLSchema#dateTime"]', michael@0: ' }', michael@0: ' } ]]', michael@0: '}'); michael@0: michael@0: LD("json_ld_fake", michael@0: '{', michael@0: ' [property "@fake"]: [string "@fake"],', michael@0: ' [property "@contextual"]: [string "@identifier"],', michael@0: ' [property "user@domain.com"]: [string "@graphical"],', michael@0: ' [property "@ID"]: [string "@@ID"]', michael@0: '}'); michael@0: })();