Skip to content

Commit

Permalink
Finish all unit testing for tokenizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazywei committed May 25, 2015
1 parent c5691e6 commit 63fc6b7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tokenzier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,66 @@ var _ = Describe("Tokenzier", func() {
}
})

It("should extract JavaScript tokens", func() {

tokenTests := []struct {
file string
tokens []string
}{
{"test_samples/JavaScript/hello.js", []string{
`(`, `function`, `(`, `)`, `{`, `console.log`, `(`, `)`, `;`, `}`,
`)`, `.call`, `(`, `this`, `)`, `;`}},
}

for _, tokenTest := range tokenTests {
fileContent, err := ioutil.ReadFile(tokenTest.file)
if err != nil {
panic(err)
}
Expect(ExtractTokens(string(fileContent))).To(Equal(tokenTest.tokens))
}
})

It("should extract JSON tokens", func() {

tokenTests := []struct {
file string
tokens []string
}{
{"test_samples/JSON/product.json", []string{
`{`, `[`, `]`, `{`, `}`, `}`}},
}

for _, tokenTest := range tokenTests {
fileContent, err := ioutil.ReadFile(tokenTest.file)
if err != nil {
panic(err)
}
Expect(ExtractTokens(string(fileContent))).To(Equal(tokenTest.tokens))
}
})
It("should extract Ruby tokens", func() {

tokenTests := []struct {
file string
tokens []string
}{
{"test_samples/Ruby/foo.rb", []string{
`module`, `Foo`, `end`}},

{"test_samples/Ruby/Rakefile", []string{
`task`, `default`, `do`, `puts`, `end`}},
}

for _, tokenTest := range tokenTests {
fileContent, err := ioutil.ReadFile(tokenTest.file)
if err != nil {
panic(err)
}
Expect(ExtractTokens(string(fileContent))).To(Equal(tokenTest.tokens))
}
})

})

Describe("extract shebang", func() {
Expand Down

0 comments on commit 63fc6b7

Please sign in to comment.