diff --git a/.gitignore b/.gitignore index f7ec627..a0dd199 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +node_modules +coverage.html + # Linux !.gitignore *~ diff --git a/.travis.yml b/.travis.yml index 12b2631..df63076 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: - - 0.8 - - 0.6 + - "0.10" + - "0.8" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ce5f33e --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +TESTS = test/*.js +REPORTER = spec +TIMEOUT = 2000 + +test: + @NODE_ENV=test ./node_modules/mocha/bin/mocha \ + --reporter $(REPORTER) \ + --timeout $(TIMEOUT) \ + $(MOCHA_OPTS) \ + $(TESTS) + +test-cov: + @$(MAKE) test REPORTER=dot + @$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html + @$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov + +test-coveralls: + @$(MAKE) test + @echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID) + @$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js + +test-all: test test-cov + +.PHONY: test test-cov test-all diff --git a/han.js b/han.js index 222b963..bb0a047 100644 --- a/han.js +++ b/han.js @@ -1 +1 @@ -module.exports = exports = require('./lib'); \ No newline at end of file +module.exports = require('./lib'); diff --git a/lib/index.js b/lib/index.js index 7ae8baa..4db8fe0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,4 +2,4 @@ var translate = require('./translate') module.exports = exports = { letter: translate.letter , pinyin: translate.pinyin -} \ No newline at end of file +} diff --git a/package.json b/package.json index 04d0073..3973d6c 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,46 @@ "name": "han", "description": "a module for tanslating Chinese(汉字) into pinyin", "version": "0.0.7", - "author": { - "name": "Sofish Lin", - "email": "sofish@me.com" - }, + "author": "Sofish Lin ", "dependencies": {}, - "devDependencies": {}, - "keywords": ["han", "pinyin", "url"], + "devDependencies": { + "mocha": "*", + "should": "*", + "blanket": "*", + "travis-cov": "*", + "mocha-lcov-reporter": "*", + "coveralls": "*" + }, + "keywords": [ + "han", + "pinyin", + "url" + ], "repository": { "type": "git", "url": "git://github.com/sofish/han.git" }, + "config": { + "blanket": { + "pattern": "han/lib", + "data-cover-flags": { + "debug": false + } + }, + "travis-cov": { + "threshold": 98 + } + }, "main": "han", - "bin": {}, - "scripts": {}, + "scripts": { + "test": "make test" + }, "engines": { "node": "*" - } + }, + "bugs": { + "url": "https://github.com/sofish/han/issues" + }, + "homepage": "https://github.com/sofish/han", + "license": "MIT" } diff --git a/readme.md b/readme.md index a0f31ea..e94bf1e 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,7 @@ # Han(汉) [![Build Status](https://travis-ci.org/sofish/han.png)](https://travis-ci.org/sofish/han) +[![Coverage Status](https://coveralls.io/repos/sofish/han/badge.png)](https://coveralls.io/r/sofish/han) a module for tanslating Chinese(汉字) into pinyin. @@ -63,7 +64,7 @@ Beause that a Chinese word always having more than one pronunciation. You may wa $ npm install han # or git clone git://github.com/sofish/han.git -$ cd node_modules/han && node testcase.js +$ cd node_modules/han && make test ``` ## Translating Messy Code diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..0a358c5 --- /dev/null +++ b/test/test.js @@ -0,0 +1,59 @@ +var han = require('../') +var should = require('should'); + +describe('han', function () { + it('letter should ok', function () { + han.letter('中文').should.be.equal('zhongwen'); + var expect = 'yao-shi-xian-speaker-deck-na-zhong-zhong-wen-zhuan-pin-yin-de'; + han.letter('要实现 Speaker Deck 那种中文转拼音的', '-').should.be.equal(expect); + }); + + it('letter with 特殊符号', function () { + han.letter('中aaaaa中¢∞§¶•誩aa文喳aa').should.be.equal('zhongaaaaa4e2da2221ea7b62022jingaawenzhaaa'); + han.letter('中EnglishWords¢∞§¶•ªº文', '-').should.be.equal('zhong-englishwords-221ea7b6-2022aaba-wen'); + }); + + it('letter with empty', function () { + // 空 + han.letter('中文', ' ').should.be.equal('zhong wen'); + han.letter('中文', '').should.be.equal('zhongwen'); + }); + + it('pinyin should ok', function () { + han.pinyin('My Chinese name is 小鱼(sofish)').should.be.eql([ + 'My Chinese name is ', + [ 'xǐao' ], + [ 'yú' ], + '(sofish)' + ]); + var expect = [ + '#$%^&*', + [ 'zhōng', 'zhòng' ], + '23¢∞§¶•ª52849', + [ 'wén', 'wèn' ], + '@#$%^&*(', + [ 'yì' ], + [ 'sī', 'sì', 'sāi' ], + ',', + [ 'húan', 'hái', 'xúan' ], + [ 'yǒu', 'yòu' ], + [ 'yīng', 'yāng' ], + [ 'wén', 'wèn' ], + ':english' + ]; + han.pinyin('#$%^&*中23¢∞§¶•ª52849文@#$%^&*(意思,还有英文:english').should.be.eql(expect); + }); + + it('pinyin with empty', function () { + han.pinyin('').should.be.eql([]); + }); + + it('pinyin with english only', function () { + han.pinyin('words like 1234567890 only').should.be.eql(['words like 1234567890 only']); + }); + + it('pinyin with english and 特殊符号', function () { + var expect = ['English words and ∞§¶•ª will always return itself']; + han.pinyin('English words and ∞§¶•ª will always return itself').should.be.eql(expect); + }); +});