Permalink
Browse files

Add RomajiParser#getState

  • Loading branch information...
1 parent ac2586b commit 900c02db609611f51adca5936341ad77f9c4b232 @kaineer committed Mar 20, 2012
Showing with 32 additions and 1 deletion.
  1. +7 −0 lib/js/kana-romaji-parser.js
  2. +25 −1 spec/kana_romaji_parser_spec.js
@@ -4,6 +4,7 @@
Kana.RomajiParser = (function(){
var Parser = function(source) {
this.buffer = new Kana.ParseBuffer(source.toUpperCase());
+ this.state = "undefined";
return this;
};
@@ -92,10 +93,16 @@ Kana.RomajiParser = (function(){
break;
}
}
+
+ this.state = (this.buffer.getSource() == "") ? "success" : "failure";
+
return this;
},
getResult: function() {
return this.buffer.getSyllables();
+ },
+ getState: function() {
+ return this.state;
}
});
@@ -3,6 +3,8 @@ describe("Kana.RomajiParser", function() {
var parser;
var expected;
+ var suffix = "";
+
var parse = function(string) {
var parser = new Kana.RomajiParser(string);
parser.parse();
@@ -47,8 +49,30 @@ describe("Kana.RomajiParser", function() {
it("should empty buffer source", function() {
expect(parser.buffer.getSource()).toEqual("");
- })
+ });
+
+ it("should have 'success' state", function() {
+ expect(parser.getState()).toEqual("success");
+ });
});
});
});
+
+ describe("parsing partial romaji", function() {
+ beforeEach(function() {
+ parser = parse("sak");
+ });
+
+ it("should return [\"SA\"]", function() {
+ expect(parser.getResult()).toEqual(["SA"]);
+ });
+
+ it("should keep K in buffer", function() {
+ expect(parser.buffer.getSource()).toEqual("K");
+ });
+
+ it("should have 'failure' state", function() {
+ expect(parser.getState()).toEqual("failure");
+ });
+ });
});

0 comments on commit 900c02d

Please sign in to comment.