From 78249fb4f139aab3e371ecfd5769e1c9ebc4c0a4 Mon Sep 17 00:00:00 2001 From: dhrname Date: Mon, 2 Feb 2015 23:28:00 +0900 Subject: [PATCH] New a parse method in the object --- org/w3c/dom/smil.js | 27 +++++++++++++++++++++++++++ tool/Spec/spec/SvgDomSpec.js | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index 79d20e6..77c3b4d 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -195,6 +195,9 @@ base("$frame").mix ( { /*開始時刻やタイミングが書かれた文字列*/ string: "", + /*イベントやindefinteで未解決かどうか*/ + isResolved: false, + /*trim メソッド * 文字列中の空白を除去*/ trim: function() { @@ -215,6 +218,7 @@ base("$frame").mix ( { plusminus = _float = sec = min = h = void 0; return s; + /*00:00:0と00:0と、0sなどの文字列をミリ秒へ変換*/ function sec() { return ( 1000*( _float(str.match(/[\d.]+s$/) || "0") || _float(str.match(/[\d.]+$/) || "0") ) ); }; @@ -245,6 +249,29 @@ base("$frame").mix ( { event: str }; } + }, + + /*parse メソッド + * stringプロパティを解析して、時刻を算出し、結果を$frame::beginプロパティに出力*/ + parse: function() { + this.begin = 0; + var str = this.trim(), + plusminus = str.search(/[\+\-]/), + event = ""; + if (plusminus > 0) { + /*Event-Value +/- Clock-Value の場合*/ + this.begin = this.offset( str.slice(plusminus) ); + event = this.event(str); + } else if ( /[^\+\-\d]/.test(str.charAt(0)) ) { + /*Event-Valuen のみの場合*/ + event = this.event(str); + } else { + /*+/- Clock-Value のみの場合*/ + this.begin = this.offset( str ); + /*イベントもindefiniteもないので、解決済みと考える*/ + this.isResolved = true; + } + return this; } } ); } ); diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index 28ee4de..856c58c 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -2118,6 +2118,7 @@ describe("SMIL Animation Spec", function() { /*境界条件を調べておく (limit value analysis)*/ it("should be this for the value (limit value analysis)", function() { expect(begin.string).toBe(""); + expect(begin.isResolved).toBeFalsy(); } ); /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ it("should be this for the value (the valid partion)", function() { @@ -2314,7 +2315,43 @@ describe("SMIL Animation Spec", function() { expect(evt.event).toBe(""); evt = begin.event("id."); expect(evt.id).toBe(""); - expect(evt.event).toBe(""); } ); + expect(evt.event).toBe(""); + } ); + } ); + + describe("An parse method in $begin object", function() { + beforeEach( function() { + begin.string = ""; + } ); + /*境界条件を調べておく (limit value analysis)*/ + it("should be this for the value (limit value analysis)", function() { + expect(begin.parse().begin).toEqual(0); + begin.string="+0"; + expect(begin.parse().begin).toEqual(0); + begin.string = "+1"; + expect(begin.parse().begin).toEqual(1000); + begin.string = " "; + expect(begin.parse().begin).toEqual(0); + begin.string = "1"; + expect(begin.parse().begin).toEqual(1000); + begin.string = "+1ms"; + expect(begin.parse().begin).toEqual(1); + begin.string = "-1ms"; + expect(begin.parse().begin).toEqual(-1); + } ); + /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ + it("should be this for the value (the valid partion)", function() { + begin.string = " 1 0 0 m s"; + expect(begin.parse().begin).toEqual(100); + begin.string = "ms"; + begin.isResolved = false; + expect(begin.parse().begin).toEqual(0); + expect(begin.isResolved).toBeFalsy(); + } ); + /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/ + it("should be this for the value (the invalid partion)", function() { + + } ); } ); } ); } ) -- 2.11.0