[Pkg-javascript-commits] [dojo] 36/149: add unit test in for trailing spaces in number. refs #18466

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository dojo.

commit 7859a00de6cc664cb7447366d3c155a4fa1864b7
Author: Clément Mathieu <clement.mathieu at outlook.com>
Date:   Wed Feb 11 13:43:17 2015 +0100

    add unit test in for trailing spaces in number. refs #18466
---
 tests/unit/number.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/tests/unit/number.js b/tests/unit/number.js
index 2c98841..fb2cd8f 100644
--- a/tests/unit/number.js
+++ b/tests/unit/number.js
@@ -12,6 +12,12 @@ define([
 		assert.notStrictEqual(value, value);
 	}
 
+	function isStrictNaN(value) {
+		// reliable test for NaN (not subject to coercion)
+		// isNaN(undefined) return true in Chrome 40
+		return value !== value;
+	}
+
 	function decimalNumberDiff(num1, num2) {
 		//TODO: should be more accurate when dojo/number finish rounding in the future
 		var diffBound = 1e-3;
@@ -38,8 +44,10 @@ define([
 
 		var str = pattern == null ? 'default' : pattern;
 		var result = number.format(sourceInput, options);
-		if (expected == null) {
-		    assert.strictEqual(result, expected);
+		if (isStrictNaN(expected)) {
+			assertStrictNaN(result);
+		} else {
+			assert.strictEqual(result, expected);
 		}
 		if (backwardCheck) {
 			var resultParsed = number.parse(result,options);
@@ -61,8 +69,10 @@ define([
 		//print('input:' + sourceInput);
 		var result = number.parse(sourceInput, options);
 		//print('result :' + result);
-		if (expected != null){
-		    assert.strictEqual(result, expected);
+		if (isStrictNaN(expected)) {
+			assertStrictNaN(result);
+		} else {
+			assert.strictEqual(result, expected);
 		}
 	}
 
@@ -343,6 +353,36 @@ define([
 				assert.strictEqual(number.parse('123.4', {places:1, locale: 'en-us'}), 123.4);
 				assert.strictEqual(number.parse('123.45', {places:'1,3', locale: 'en-us'}), 123.45);
 				assert.strictEqual(number.parse('123.45', {places:'0,2', locale: 'en-us'}), 123.45);
+			},
+			't18466': function () {
+				var locale = "fr";
+				checkParse({ pattern: "#,###.00 ¤;(#,###.00) ¤", locale: locale }, "1,00 ", NaN);
+				checkParse({ pattern: "#,###.00 ¤;(#,###.00) ¤", locale: locale }, "1,00", 1);
+				checkParse({ pattern: "#,###.00¤;(#,###.00)¤", locale: locale }, "1,00 ", NaN);
+				checkParse({ pattern: "#,###.00¤;(#,###.00)¤", locale: locale }, "1,00", 1);
+				checkParse({ pattern: "#,###.00 ¤;(#,###.00) ¤", locale: locale }, "1 000,00 ", NaN);
+				checkParse({ pattern: "#,###.00 ¤;(#,###.00) ¤", locale: locale }, "1 000,00", 1000);
+				checkParse({ pattern: "#,###.00¤;(#,###.00)¤", locale: locale }, "1 000,00 ", NaN);
+				checkParse({ pattern: "#,###.00¤;(#,###.00)¤", locale: locale }, "1 000,00", 1000);
+				checkFormatParseCycle({ pattern: "#,###.00 ¤;(#,###.00) ¤", locale: locale }, "1200", "1\xa0200,00", true)
+				checkFormatParseCycle({ pattern: "#,###.00¤;(#,###.00)¤", locale: locale }, "1200", "1\xa0200,00", true)
+				checkFormatParseCycle({ pattern: "#,###.00 ¤;(#,###.00) ¤", locale: locale }, "1200 ", "1\xa0200,00", true)
+				checkFormatParseCycle({ pattern: "#,###.00¤;(#,###.00)¤", locale: locale }, "1200 ", "1\xa0200,00", true)
+
+				checkParse({ pattern: "¤ #,###.00;¤ (#,###.00)", locale: locale }, " 1,00", NaN);
+				checkParse({ pattern: "¤ #,###.00;¤ (#,###.00)", locale: locale }, "1,00", 1);
+				checkParse({ pattern: "¤#,###.00;¤(#,###.00)", locale: locale }, " 1,00", NaN);
+				checkParse({ pattern: "¤#,###.00;¤(#,###.00)", locale: locale }, "1,00", 1);
+				checkParse({ pattern: "¤ #,###.00;¤ (#,###.00)", locale: locale }, " 1 000,00", NaN);
+				checkParse({ pattern: "¤ #,###.00;¤ (#,###.00)", locale: locale }, "1 000,00", 1000);
+				checkParse({ pattern: "¤#,###.00;¤(#,###.00)", locale: locale }, " 1 000,00", NaN);
+				checkParse({ pattern: "¤#,###.00;¤(#,###.00)", locale: locale }, "1 000,00", 1000);
+				checkFormatParseCycle({ pattern: "¤ #,###.00;¤ (#,###.00)", locale: locale }, "1200", "1\xa0200,00", true)
+				checkFormatParseCycle({ pattern: "¤#,###.00;¤(#,###.00)", locale: locale }, "1200", "1\xa0200,00", true)
+				checkFormatParseCycle({ pattern: "¤ #,###.00;¤ (#,###.00)", locale: locale }, " 1200", "1\xa0200,00", true)
+				checkFormatParseCycle({ pattern: "¤#,###.00;¤(#,###.00)", locale: locale }, " 1200 ", "1\xa0200,00", true)
+
+
 			}
 		},
 
@@ -410,14 +450,14 @@ define([
 
 
 			// NumberRegression.Test4052223
-			checkParse({ pattern: '#,#00.00' }, 'abc3');
+			checkParse({ pattern: '#,#00.00' }, 'abc3', NaN);
 
 			//TODO: got NaN instead of 1.222, is it ok?
 			//checkParse({pattern:'#,##0.###',locale:'en-us'},'1.222,111',1.222);
 			//checkParse({pattern:'#,##0.###',locale:'en-us'},'1.222x111',1.222);
 
 			//got NaN for illegal input, ok
-			checkParse(null,'hello: ,.#$@^&**10x');
+			checkParse(null,'hello: ,.#$@^&**10x', NaN);
 
 
 			// NumberRegression.Test4125885

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list