Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from stasm/ontheflycompiler
Add the on-the-fly compiler
- Loading branch information
Showing
12 changed files
with
837 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
var fs = require('fs'); | ||
var should = require('should'); | ||
var Compiler = require('../../../js/compiler.js'); | ||
|
||
function read(filename) { | ||
return JSON.parse(fs.readFileSync(filename)).body; | ||
} | ||
|
||
describe('Basic entities', function(){ | ||
var ast; | ||
var obj; | ||
|
||
beforeEach(function() { | ||
obj = {}; | ||
Compiler.compile(ast, obj); | ||
}); | ||
|
||
describe('Simple value', function(){ | ||
var filename = './lol/basic1.json'; | ||
before(function() { | ||
ast = read(filename); | ||
}); | ||
|
||
describe('Simple string value', function(){ | ||
it('is "Simple"', function(){ | ||
var value = obj['basic1'].get(); | ||
value.should.equal("Basic 1"); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Simple array', function(){ | ||
var filename = './lol/basic2.json'; | ||
before(function() { | ||
ast = read(filename); | ||
}); | ||
|
||
describe('an array without an index', function(){ | ||
it('is "One" when called without an index', function(){ | ||
var value = obj['basic21'].get(obj); | ||
value.should.equal('One'); | ||
}); | ||
it('is "Two" when called with [1]', function(){ | ||
var value = obj['basic21'].get(obj, {}, [1]); | ||
value.should.equal('Two'); | ||
}); | ||
}); | ||
describe('an array with an index of [1]', function(){ | ||
it('is "Two" when called without an index', function(){ | ||
var value = obj['basic22'].get(obj); | ||
value.should.equal('Two'); | ||
}); | ||
it('is "One" when called with [0]', function(){ | ||
var value = obj['basic22'].get(obj, {}, [0]); | ||
value.should.equal('One'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Simple hash', function(){ | ||
var filename = './lol/basic3.json'; | ||
before(function() { | ||
ast = read(filename); | ||
}); | ||
|
||
describe('a hash with no index and no default value', function(){ | ||
it('is "Firefox"', function(){ | ||
var value = obj['brandName1'].get(obj); | ||
value.should.equal('Firefox'); | ||
}); | ||
it('is "Aurora when called with an index of ["feminine"] "', function(){ | ||
var value = obj['brandName1'].get(obj, {}, ['feminine']); | ||
value.should.equal('Aurora'); | ||
}); | ||
}); | ||
describe('a hash with no index and with a default value', function(){ | ||
it('is "Aurora"', function(){ | ||
var value = obj['brandName2'].get(obj); | ||
value.should.equal('Aurora'); | ||
}); | ||
it('is "Firefox" when called with an index of ["masculine"] ', function(){ | ||
var value = obj['brandName2'].get(obj, {}, ['masculine']); | ||
value.should.equal('Firefox'); | ||
}); | ||
}); | ||
describe('a hash with an index and no default value', function(){ | ||
it('is "Aurora"', function(){ | ||
var value = obj['brandName3'].get(obj); | ||
value.should.equal('Aurora'); | ||
}); | ||
it('is "Firefox" when called with an index of ["masculine"] ', function(){ | ||
var value = obj['brandName3'].get(obj, {}, ['masculine']); | ||
value.should.equal('Firefox'); | ||
}); | ||
}); | ||
describe('a hash with too many index keys and no default value', function(){ | ||
it('is "Aurora"', function(){ | ||
var value = obj['brandName3'].get(obj); | ||
value.should.equal('Aurora'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
HERE=$(cd `dirname $0`; pwd) | ||
LOLS=$HERE/lol | ||
L20N=$HOME/moz/code/l20n | ||
|
||
source $L20N/@l20n/bin/activate | ||
|
||
DUMP=$L20N/l20n/python/tools/dump_lol.py | ||
OPTS="-t json" | ||
|
||
for LOL in $(ls -1 $LOLS/*.lol); | ||
do | ||
NAME=$(basename $LOL .lol); | ||
python $DUMP $OPTS $LOL > $LOLS/${NAME}.json | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"type": "LOL", | ||
"body": [ | ||
{ | ||
"type": "Entity", | ||
"id": { | ||
"type": "Identifier", | ||
"name": "basic1" | ||
}, | ||
"index": [], | ||
"value": { | ||
"type": "String", | ||
"content": "Basic 1" | ||
}, | ||
"attrs": {}, | ||
"local": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<basic1 "Basic 1"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"type": "LOL", | ||
"body": [ | ||
{ | ||
"type": "Entity", | ||
"id": { | ||
"type": "Identifier", | ||
"name": "basic21" | ||
}, | ||
"index": [], | ||
"value": { | ||
"type": "Array", | ||
"content": [ | ||
{ | ||
"type": "String", | ||
"content": "One" | ||
}, | ||
{ | ||
"type": "String", | ||
"content": "Two" | ||
} | ||
] | ||
}, | ||
"attrs": {}, | ||
"local": false | ||
}, | ||
{ | ||
"type": "Entity", | ||
"id": { | ||
"type": "Identifier", | ||
"name": "basic22" | ||
}, | ||
"index": [ | ||
{ | ||
"type": "Literal", | ||
"value": 1 | ||
} | ||
], | ||
"value": { | ||
"type": "Array", | ||
"content": [ | ||
{ | ||
"type": "String", | ||
"content": "One" | ||
}, | ||
{ | ||
"type": "String", | ||
"content": "Two" | ||
} | ||
] | ||
}, | ||
"attrs": {}, | ||
"local": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<basic21 ['One', 'Two']> | ||
<basic22[1] ['One', 'Two']> |
Oops, something went wrong.