forked from zaach/jsxgettext
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 zaach#7 from ozten/join-existing-tests
Add tests for --join-existing.
- Loading branch information
Showing
10 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
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 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 |
---|---|---|
|
@@ -17,5 +17,8 @@ | |
"optionalDependencies": {}, | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"scripts": { | ||
"test": "node tests/all.js" | ||
} | ||
} |
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,9 @@ | ||
|
||
## Join Existing tests | ||
|
||
The following commands created tests/outputs/messages_first | ||
|
||
xgettext -L Perl --output-dir=tests/outputs/ --from-code=utf-8 --output=messages_firstpass.pot tests/inputs/first.js | ||
|
||
xgettext -L Perl --output-dir=tests/outputs/ --from-code=utf-8 --output=messages_new.pot tests/inputs/first.js | ||
xgettext -j -L Perl --output-dir=tests/outputs/ --from-code=utf-8 --output=messages_new.pot tests/inputs/second.js |
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,12 @@ | ||
// TODO figure out why | ||
// exports['test join_existing'] = require('./join_existing'); | ||
// doesn't work | ||
exports['test join_existing'] = require('./join_existing')['we gettext from first file']; | ||
|
||
if (module == require.main) { | ||
require('test').run(exports); | ||
} else { | ||
console.log("Just a module"); | ||
} | ||
|
||
|
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 @@ | ||
var msg = gettext('Hello World'); | ||
var dup = gettext('This message is used twice.'); |
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 @@ | ||
var dup = gettext('This message is used twice.'); |
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,96 @@ | ||
var | ||
fs = require('fs'), | ||
jsxgettext = require('../lib/jsxgettext'), | ||
path = require('path'); | ||
|
||
// Tests the --join-existing feature | ||
|
||
/* | ||
* We use xgettext on files under inputs and save it's output | ||
* under outputs. These tests run jsxgettext against the | ||
* same inputs and test for identical output. | ||
*/ | ||
|
||
var sourceFirstPass; | ||
|
||
exports['we gettext from first file'] = function (assert, cb) { | ||
// We'll extract strings from inputs/first.js | ||
// This should match outputs/messages_firstpass.js | ||
var inputFilename = path.join(__dirname, 'inputs', 'first.js'); | ||
fs.readFile(inputFilename, function (err, source) { | ||
var opts = {}, | ||
sources = {'inputs/first.js': source}, | ||
result = jsxgettext.generate(sources, 'inputs/first.js', opts); | ||
assert.equal(typeof result, 'string'); | ||
assert.ok(result.length > 0); | ||
var outputFilename = path.join(__dirname, 'outputs', | ||
'messages_firstpass.pot'); | ||
fs.readFile(outputFilename, function (err, source) { | ||
assert.ok(! err); | ||
|
||
var example = source.toString('utf8').split('\n'); | ||
var actual = result.split('\n'); | ||
|
||
for (var i=0; i < example.length; i++) { | ||
// Dynamic lines | ||
if (0 === example[i].indexOf('"POT-Creation-Date')) continue; | ||
|
||
// Reproducable lines | ||
assert.ok(i < actual.length, | ||
'Num example output is at least as long as our result'); | ||
assert.equal(actual[i], example[i], 'We match line for line'); | ||
} | ||
assert.ok((actual.length == example.length || | ||
actual.length - 1 == example.length), | ||
'Actual and Expected are the same length'); | ||
}); | ||
|
||
sourceFirstPass = source; | ||
|
||
// write to filesystem as join-existing will implicitly look for it, but... | ||
// TODO: So jsxgettext does the right thing with or without messages.po | ||
// that seems odd... | ||
fs.writeFileSync('messages.pot', result, "utf8"); | ||
//cb(); | ||
test2(assert, cb); | ||
}); | ||
}; | ||
|
||
var test2 = function (assert, cb) { | ||
// We'll extract strings from inputs/second.js | ||
// This should match outputs/messages.js | ||
var inputFilename = path.join(__dirname, 'inputs', 'second.js'); | ||
fs.readFile(inputFilename, function (err, source) { | ||
var opts = {"join-existing": true}, | ||
sources = {'inputs/first.js': sourceFirstPass, | ||
'inputs/second.js': source}, | ||
result = jsxgettext.generate(sources, 'inputs/second.js', opts); | ||
|
||
assert.equal(typeof result, 'string'); | ||
assert.ok(result.length > 0); | ||
var outputFilename = path.join(__dirname, 'outputs', | ||
'messages_secondpass.pot'); | ||
fs.readFile(outputFilename, function (err, source) { | ||
assert.ok(! err); | ||
|
||
var example = source.toString('utf8').split('\n'); | ||
var actual = result.split('\n'); | ||
|
||
for (var i=0; i < example.length; i++) { | ||
// Dynamic lines | ||
if (0 === example[i].indexOf('"POT-Creation-Date')) continue; | ||
// Reproducable lines | ||
assert.ok(i < actual.length, | ||
'Num example output is at least as long as our result'); | ||
assert.equal(actual[i], example[i], 'We match line for line'); | ||
} | ||
assert.ok((actual.length == example.length || | ||
actual.length - 1 == example.length), | ||
'Actual and Expected are the same length'); | ||
fs.writeFileSync('messages2.pot', result, "utf8"); | ||
}); | ||
cb(); | ||
}); | ||
}; | ||
|
||
if (module == require.main) require('test').run(exports); |
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,26 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2012-07-16 18:17-0700\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <LL@li.org>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
|
||
#: inputs/first.js:1 | ||
msgid "Hello World" | ||
msgstr "" | ||
|
||
#: inputs/first.js:2 | ||
msgid "This message is used twice." | ||
msgstr "" |
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,26 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2012-07-17 17:39-0700\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <LL@li.org>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
|
||
#: inputs/first.js:1 | ||
msgid "Hello World" | ||
msgstr "" | ||
|
||
#: inputs/first.js:2 inputs/second.js:1 | ||
msgid "This message is used twice." | ||
msgstr "" |