-
Notifications
You must be signed in to change notification settings - Fork 34
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 #7 from JacksonTian/add_unit_test
添加单元测试
- Loading branch information
Showing
8 changed files
with
126 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
node_modules | ||
coverage.html | ||
|
||
# Linux | ||
!.gitignore | ||
*~ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 0.8 | ||
- 0.6 | ||
- "0.10" | ||
- "0.8" |
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,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 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = exports = require('./lib'); | ||
module.exports = require('./lib'); |
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 |
---|---|---|
|
@@ -2,21 +2,46 @@ | |
"name": "han", | ||
"description": "a module for tanslating Chinese(汉字) into pinyin", | ||
"version": "0.0.7", | ||
"author": { | ||
"name": "Sofish Lin", | ||
"email": "[email protected]" | ||
}, | ||
"author": "Sofish Lin <[email protected]>", | ||
"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" | ||
} |
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 |
---|---|---|
@@ -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); | ||
}); | ||
}); |