/trunk/api/js/dojo1.0/dijit/tests/i18n/number.html |
---|
New file |
0,0 → 1,214 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>Test NumberTextBox</title> |
<script type="text/javascript" src="../../../dojo/dojo.js" |
djConfig="isDebug: true, extraLocale: ['zh-cn','fr-fr','ar-eg','hi-in']"></script> |
<script type="text/javascript" src="../../../dojo/currency.js"></script> |
<script type="text/javascript" src="../../../dojo/number.js"></script> |
<script type="text/javascript"> |
dojo.require("dijit.form.NumberTextBox"); |
dojo.require("dijit.form.CurrencyTextBox"); |
dojo.require("dijit.form.DateTextBox"); |
dojo.require("dijit.form.ValidationTextBox"); |
dojo.require("dojo.date.locale"); |
dojo.require("dojo.date.stamp"); |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
dojo.require("doh.runner"); |
</script> |
<script src="test_i18n.js"></script> |
<script type="text/javascript"> |
dojo.addOnLoad(function(){ |
doh.register("t", getAllTestCases()); |
doh.run(); |
}); |
</script> |
<style type="text/css"> |
@import "../../../dojo/resources/dojo.css"; |
@import "../../themes/tundra/tundra.css"; |
@import "../css/dijitTests.css"; |
.title { |
background-color:#ddd; |
} |
.hint { |
background-color:#eee; |
} |
.testExample { |
background-color:#fbfbfb; |
padding:1em; |
margin-bottom:1em; |
border:1px solid #bfbfbf; |
} |
.dojoTitlePaneLabel label { |
font-weight:bold; |
} |
td {white-space:nowrap} |
</style> |
</head> |
<body class="tundra"> |
<h1 class="testTitle">Dijit TextBox Globalization Test for Number</h1> |
<!-- <h2 class="testTitle">Press the following button to start all test after this page is loaded.</h2> |
<button id="startButton" onclick="startTest()">Start Test</button>--> |
<p> |
Before start this test, make sure the <b>dojo/cldr/nls</b> contains the data for "zh-cn", "fr-fr", "ar-eg" and "hi-in". If not, convert these CLDR data and put them there. |
</p> |
<script> |
(function() { |
genFormatTestCases("Number Format", "dijit.form.NumberTextBox", [ |
{ attrs: {lang: "zh-cn"}, |
desc: "Locale: zh_CN", |
value: "12345.067", |
expValue: "12,345.067", |
comment: "" |
}, |
{ attrs: {lang: "zh-cn"}, |
desc: "Locale: zh_CN", |
value: "-12345.067", |
expValue: "-12,345.067", |
comment: "" |
}, |
{ attrs: {lang: "fr-fr"}, |
desc: "Locale: fr_FR", |
value: "12345.067", |
expValue: "12 345,067", |
comment: "Failed in IE. The currency textbox should not reject the value generated by itself. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>" |
}, |
{ attrs: {lang: "fr-fr"}, |
desc: "Locale: zh_CN", |
value: "-12345.067", |
expValue: "-12 345,067", |
comment: "Failed in IE. The currency textbox should not reject the value generated by itself. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>" |
}, |
{ attrs: {lang: "ar-eg"}, |
desc: "Locale: ar_EG", |
value: "12345.067", |
expValue: "12٬345٫067", |
comment: "" |
}, |
{ attrs: {lang: "ar-eg"}, |
desc: "Locale: ar_EG", |
value: "-12345.067", |
expValue: "12٬345٫067-", |
comment: "" |
}, |
{ attrs: {lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: ar_EG", |
value: "12345.067", |
expValue: "١٢\u066C٣٤٥\u066B٠٦٧", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
}, |
{ attrs: {lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: ar_EG", |
value: "-12345.067", |
expValue: "١٢\u066C٣٤٥\u066B٠٦٧-", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
}, |
{ attrs: {lang: "hi-in", constraints: "{localeDigit: true}"}, |
desc: "Locale: hi_IN", |
value: "123456789.068", |
expValue: "१२,३४,५६,७८९.०६८", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
}, |
{ attrs: {lang: "hi-in", constraints: "{localeDigit: true}"}, |
desc: "Locale: hi_IN", |
value: "-123456789.068", |
expValue: "-१२,३४,५६,७८९.०६८", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
} |
]); |
genValidateTestCases("Number Validate", "dijit.form.NumberTextBox", [ |
{ attrs: {lang: "zh-cn"}, |
desc: "Locale: zh_CN", |
value: 12345.067, |
expValue: "12,345.067", |
comment: "" |
}, |
{ attrs: {lang: "zh-cn"}, |
desc: "Locale: zh_CN", |
value: -12345.067, |
expValue: "-12,345.067", |
comment: "" |
}, |
{ attrs: {lang: "fr-fr"}, |
desc: "Locale: fr_FR", |
value: 12345.067, |
expValue: "12 345,067", |
comment: "Failed in IE. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>" |
}, |
{ attrs: {lang: "fr-fr"}, |
desc: "Locale: zh_CN", |
value: -12345.067, |
expValue: "-12 345,067", |
comment: "Failed in IE. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>" |
}, |
{ attrs: {lang: "ar-eg"}, |
desc: "Locale: ar_EG", |
value: 12345.067, |
expValue: "12٬345٫067", |
comment: "" |
}, |
{ attrs: {lang: "ar-eg"}, |
desc: "Locale: ar_EG", |
value: -12345.067, |
expValue: "12٬345٫067-", |
comment: "" |
}, |
{ attrs: {lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: ar_EG", |
value: 12345.067, |
expValue: "١٢\u066C٣٤٥\u066B٠٦٧", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
}, |
{ attrs: {lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: ar_EG", |
value: -12345.067, |
expValue: "١٢\u066C٣٤٥\u066B٠٦٧-", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
}, |
{ attrs: {lang: "hi-in", constraints: "{localeDigit: true}"}, |
desc: "Locale: hi_IN", |
value: 123456789.068, |
expValue: "१२,३४,५६,७८९.०६८", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
}, |
{ attrs: {lang: "hi-in", constraints: "{localeDigit: true}"}, |
desc: "Locale: hi_IN", |
value: -123456789.068, |
expValue: "-१२,३४,५६,७८९.०६८", |
comment: "<a href='currency.html#cmt_2'>See #2 (currency.html).</a>" |
} |
]); |
dojo.parser.parse(); |
})(); |
</script> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dijit/tests/i18n/README |
---|
New file |
0,0 → 1,4 |
Global Verification Tests (GVT) |
In order to run these tests, you will need full locale support in Dojo. Dojo only ships with a small subset by default. |
See util/buildscripts/cldr for an ant-based build script. |
/trunk/api/js/dojo1.0/dijit/tests/i18n/currency.html |
---|
New file |
0,0 → 1,263 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>Test CurrencyTextBox</title> |
<script type="text/javascript" src="../../../dojo/dojo.js" |
djConfig="isDebug: true, extraLocale: ['zh-cn','fr-fr','ja-jp','ar-eg']"></script> |
<script type="text/javascript" src="../../../dojo/currency.js"></script> |
<script type="text/javascript" src="../../../dojo/number.js"></script> |
<script type="text/javascript"> |
dojo.require("dijit.form.NumberTextBox"); |
dojo.require("dijit.form.CurrencyTextBox"); |
dojo.require("dijit.form.DateTextBox"); |
dojo.require("dijit.form.ValidationTextBox"); |
dojo.require("dojo.date.locale"); |
dojo.require("dojo.date.stamp"); |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
dojo.require("doh.runner"); |
</script> |
<script src="test_i18n.js"></script> |
<script type="text/javascript"> |
dojo.addOnLoad(function(){ |
doh.register("t", getAllTestCases()); |
doh.run(); |
}); |
</script> |
<style type="text/css"> |
@import "../../../dojo/resources/dojo.css"; |
@import "../../themes/tundra/tundra.css"; |
@import "../css/dijitTests.css"; |
.title { |
background-color:#ddd; |
} |
.hint { |
background-color:#eee; |
} |
.testExample { |
background-color:#fbfbfb; |
padding:1em; |
margin-bottom:1em; |
border:1px solid #bfbfbf; |
} |
.dojoTitlePaneLabel label { |
font-weight:bold; |
} |
td {white-space:nowrap} |
</style> |
</head> |
<body class="tundra"> |
<h1 class="testTitle">Dijit TextBox Globalization Test for Currency</h1> |
<!-- <h2 class="testTitle">Press the following button to start all test after this page is loaded.</h2> |
<button id="startButton" onclick="startTest()">Start Test</button> --> |
<p> |
Before start this test, make sure the <b>dojo/cldr/nls</b> contains the data for "zh-cn", "fr-fr", "ja-jp" and "ar-eg" |
and currencies CNY, EGP, EUR, JPY. If not, convert these CLDR data and put them there. |
</p> |
<script> |
(function() { |
genFormatTestCases("Currency Format", "dijit.form.CurrencyTextBox", [ |
{ attrs: {Currency: "CNY", lang: "zh-cn"}, |
desc: "Locale: <b>zh_CN</b> Currency: <b>CNY</b>", |
value: "123456789.46", |
expValue: "¥123,456,789.46", |
comment: "" |
}, |
{ attrs: {Currency: "CNY", lang: "zh-cn"}, |
desc: "Locale: <b>zh_CN</b> Currency: <b>CNY</b>", |
value: "-123456789.46", |
expValue: "-¥123,456,789.46", |
comment: "" |
}, |
{ attrs: {Currency: "EUR", lang: "fr-fr"}, |
desc: "Locale: <b>fr_FR</b> Currency: <b>EUR</b>", |
value: "123456789.46", |
expValue: "123 456 789,46 €", |
comment: "Failed in IE: the currency textbox should not reject the value generated by itself. <a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {Currency: "EUR", lang: "fr-fr"}, |
desc: "Locale: <b>zh_CN</b> Currency: <b>EUR</b>", |
value: "-123456789.46", |
expValue: "-123 456 789,46 €", |
comment: "Failed in IE: the currency textbox should not reject the value generated by itself. <a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {Currency: "JPY", lang: "ja-jp"}, |
desc: "Locale: <b>ja_JP</b> Currency: <b>JPY</b>", |
value: "123456789.46", |
expValue: "¥123,456,789", |
comment: "" |
}, |
{ attrs: {Currency: "JPY", lang: "ja-jp"}, |
desc: "Locale: <b>ja_JP</b> Currency: <b>JPY</b>", |
value: "-123456789.46", |
expValue: "-¥123,456,789", |
comment: "" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: "123456789.46", |
expValue: "ج.م.\u200F 123٬456٬789٫46", |
comment: "Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: "-123456789.46", |
expValue: "ج.م.\u200F 123٬456٬789٫46-", |
comment: "Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: "123456789.46", |
expValue: "ج.م.\u200F ١٢٣\u066C٤٥٦\u066C٧٨٩\u066B٤٦", |
comment: "<a href='#cmt_3'>See #3.</a> Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: "-123456789.46", |
expValue: "ج.م.\u200F ١٢٣\u066C٤٥٦\u066C٧٨٩\u066B٤٦-", |
comment: "<a href='#cmt_3'>See #3.</a> Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
} |
]); |
genValidateTestCases("Currency Validate", "dijit.form.CurrencyTextBox", [ |
{ attrs: {Currency: "CNY", lang: "zh-cn"}, |
desc: "Locale: <b>zh_CN</b> Currency: <b>CNY</b>", |
value: 123456789.46, |
expValue: "¥123,456,789.46", |
comment: "" |
}, |
{ attrs: {Currency: "CNY", lang: "zh-cn"}, |
desc: "Locale: <b>zh_CN</b> Currency: <b>CNY</b>", |
value: -123456789.46, |
expValue: "-¥123,456,789.46", |
comment: "" |
}, |
{ attrs: {Currency: "EUR", lang: "fr-fr"}, |
desc: "Locale: <b>fr_FR</b> Currency: <b>EUR</b>", |
value: 123456789.46, |
expValue: "123 456 789,46 €", |
comment: "Failed in IE. <a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {Currency: "EUR", lang: "fr-fr"}, |
desc: "Locale: <b>zh_CN</b> Currency: <b>EUR</b>", |
value: -123456789.46, |
expValue: "-123 456 789,46 €", |
comment: "Failed in IE. <a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {Currency: "JPY", lang: "ja-jp"}, |
desc: "Locale: <b>ja_JP</b> Currency: <b>JPY</b>", |
value: 123456789, |
expValue: "¥123,456,789", |
comment: "" |
}, |
{ attrs: {Currency: "JPY", lang: "ja-jp"}, |
desc: "Locale: <b>ja_JP</b> Currency: <b>JPY</b>", |
value: -123456789, |
expValue: "-¥123,456,789", |
comment: "" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: 123456789.46, |
expValue: "ج.م.\u200F 123٬456٬789٫46", |
comment: "Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: -123456789.46, |
expValue: "ج.م.\u200F 123٬456٬789٫46-", |
comment: "Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: 123456789.46, |
expValue: "ج.م.\u200F ١٢٣\u066C٤٥٦\u066C٧٨٩\u066B٤٦", |
comment: "<a href='#cmt_3'>See #3.</a> Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {Currency: "EGP", lang: "ar-eg", constraints: "{localeDigit: true}"}, |
desc: "Locale: <b>ar_EG</b> Currency: <b>EGP</b>", |
value: -123456789.46, |
expValue: "ج.م.\u200F ١٢٣\u066C٤٥٦\u066C٧٨٩\u066B٤٦-", |
comment: "<a href='#cmt_3'>See #3.</a> Failed in Firefox. <a href='#cmt_2'>See #2.</a>" |
} |
]); |
dojo.parser.parse(); |
})(); |
</script> |
<h2 class="testTitle">Issues & Comments</h2> |
<h3 class="testTitle"><a name="cmt_1">Issue #1<sup style="color:blue">Fixed</sup></a></h3> |
<p> |
Some browsers like FireFox have a bug on the non-breaking space character (U+00A0, <b>&nbsp;</b> or <b>&#160;</b> or |
<b>&#xA0;</b> in HTML). |
They always convert the NBSP character to a normal space (U+0020, <b>&#x20;</b> in HTML) automatically in the following circumstances: |
</p> |
<ul> |
<li>Copy text from the page</li> |
<li>Use <b>innerHTML</b> to get the content of a certain element</li> |
<li>Use <b>value</b> to get an <b>INPUT</b> element's value</li> |
</ul> |
<p> |
You cannot read a real NBSP character from an <b>INPUT</b> element on these browsers. It causes issues when some formatting data in CLDR |
contains an NBSP character. For example, |
</p> |
<ul> |
<li>Many locales like French use an NBSP character as a group separator in numbers</li> |
<li>French and Finnish use NBSP characters in their percentage and currency format patterns respectively</li> |
<li>Russian uses NBSP characters in their date format pattern (see <a href="test_validateDate.html">test_validateDate.html</a>)</li> |
</ul> |
<p> |
So Dojo may generate formatted data with NBSP characters in it but cannot read NBSP charaters from user's input in some browser. |
</p> |
<h3 class="testTitle"><a name="cmt_2">Issue #2<sup style="color:blue">Fixed: the CLDR data generator should be fixed by adding code to convert U+200F to "\u200F" in nls JS files.</sup></a></h3> |
<p> |
Most Bidi currency symbols contain an LTR-MARK (U+200F) character at the very beginning. |
But Firefox ignores it when it is not in any escaping form. This should be a bug of Firefox. |
For example, click <a href="javascript:alert(''.indexOf('\u200F'))"><code>alert(''.indexOf('\u+200F'))</code></a> (there is a U+200F in the empty-looking string): |
</p> |
<ul> |
<li>In Firefox, shows "-1" -- no U+200F found</li> |
<li>In IE & Opera, shows "0" -- the U+200F is found</li> |
</ul> |
<p> |
But if the U+200F is in some escaping form, Firefox will work as well as other browsers. |
Click <a href="javascript:alert('\u200F'.indexOf('\u200F'))"><code>alert('\u200F'.indexOf('\u+200F'))</code></a> to see the same result both in Firefox and IE: |
</p> |
<h3 class="testTitle"><a name="cmt_3">Issue #3<sup style="color:blue">Fixed: added a "localeDigit" to the options</sup></a></h3> |
<p> |
Strictly speaking, the data conversion must support non-European number characters in some locales like Arabic and Hindi. |
For example, ICU formats a number data into Indic number characters by default in the Arabic locale. |
However, currently Dojo does not support this feature (Dojo uses the default number conversion of the browser). |
</p> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dijit/tests/i18n/date.html |
---|
New file |
0,0 → 1,173 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>Test DateTextBox</title> |
<script type="text/javascript" src="../../../dojo/dojo.js" |
djConfig="isDebug: true, extraLocale: ['zh-cn','fr-fr','ja-jp','ar-eg','ru-ru','hi-in','en-us']"></script> |
<script type="text/javascript" src="../../../dojo/currency.js"></script> |
<script type="text/javascript" src="../../../dojo/number.js"></script> |
<script type="text/javascript"> |
dojo.require("dijit.form.NumberTextBox"); |
dojo.require("dijit.form.CurrencyTextBox"); |
dojo.require("dijit.form.DateTextBox"); |
dojo.require("dijit.form.ValidationTextBox"); |
dojo.require("dojo.date.locale"); |
dojo.require("dojo.date.stamp"); |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
dojo.require("doh.runner"); |
</script> |
<script src="test_i18n.js"></script> |
<script type="text/javascript"> |
dojo.addOnLoad(function(){ |
doh.register("t", getAllTestCases()); |
doh.run(); |
}); |
</script> |
<style type="text/css"> |
@import "../../../dojo/resources/dojo.css"; |
@import "../../themes/tundra/tundra.css"; |
@import "../css/dijitTests.css"; |
.title { |
background-color:#ddd; |
} |
.hint { |
background-color:#eee; |
} |
.testExample { |
background-color:#fbfbfb; |
padding:1em; |
margin-bottom:1em; |
border:1px solid #bfbfbf; |
} |
.dojoTitlePaneLabel label { |
font-weight:bold; |
} |
td {white-space:nowrap} |
</style> |
<script> |
function gen4DateFormat(testCases, language, locale, date, short, shortCmt, medium, mediumCmt, long, longCmt, full, fullCmt) { |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'short', localeDigit: true}" : "{formatLength:'short'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Short</b>", |
value: date, |
expValue: short, |
comment: shortCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'medium', localeDigit: true}" : "{formatLength:'medium'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Medium</b>", |
value: date, |
expValue: medium, |
comment: mediumCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'long', localeDigit: true}" : "{formatLength:'long'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Long</b>", |
value: date, |
expValue: long, |
comment: longCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'full', localeDigit: true}" : "{formatLength:'full'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Full</b>", |
value: date, |
expValue: full, |
comment: fullCmt |
}); |
} |
</script> |
</head> |
<body class="tundra"> |
<h1 class="testTitle">Dijit TextBox Globalization Test for Date</h1> |
<!-- <h2 class="testTitle">Press the following button to start all test after this page is loaded.</h2> |
<button id="startButton" onclick="startTest()">Start Test</button>--> |
<p> |
Before start this test, make sure the <b>dojo/cldr/nls</b> contains the data for "zh-cn", "fr-fr", "ja-jp", "ru-ru", "hi-in", "en-us" and "ar-eg". If not, convert these CLDR data and put them there. |
</p> |
<script> |
(function() { |
var testCases; |
testCases = new Array(); |
gen4DateFormat(testCases, "ru-ru", "ru_RU", "2005-07-31", |
"31.07.05", "", "31.07.2005", "", "31 июля 2005 г.", "Failed in Firefox. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>", "31 июля 2005 г.", "Failed in Firefox. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>"); |
gen4DateFormat(testCases, "zh-cn", "zh_CN", "2005-07-31", |
"05-7-31", "", "2005-7-31", "", "2005年7月31日", "", "2005年7月31日星期日", ""); |
gen4DateFormat(testCases, "en-us", "en_US", "2005-07-31", |
"7/31/05", "", "Jul 31, 2005", "", "July 31, 2005", "", "Sunday, July 31, 2005", ""); |
gen4DateFormat(testCases, "fr-fr", "fr_FR", "2005-07-31", |
"31/07/05", "", "31 juil. 05", "", "31 juillet 2005", "", "dimanche 31 juillet 2005", ""); |
gen4DateFormat(testCases, "ja-jp", "ja_JP", "2005-07-31", |
"05/07/31", "", "2005/07/31", "", "2005年7月31日", "", "2005年7月31日日曜日", ""); |
gen4DateFormat(testCases, "ar-eg", "ar_EG", "2005-07-31", |
"31/7/2005", "", "31/07/2005", "", "31 يوليو, 2005", "", "الأحد, 31 يوليو, 2005", ""); |
gen4DateFormat(testCases, "hi-in", "hi_IN", "2005-07-31", |
"३१-७-०५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>", "३१-०७-२००५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>", "३१ जुलाई २००५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>", "रविवार ३१ जुलाई २००५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>"); |
genFormatTestCases("Date Format", "dijit.form.DateTextBox", testCases); |
testCases = new Array(); |
gen4DateFormat(testCases, "ru-ru", "ru_RU", new Date(2005, 6, 31), |
"31.07.05", "", "31.07.2005", "", "31 июля 2005 г.", "Failed in Firefox. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>", "31 июля 2005 г.", "Failed in Firefox. <a href='currency.html#cmt_1'>See #1 (currency.html).</a>"); |
gen4DateFormat(testCases, "zh-cn", "zh_CN", new Date(2005, 6, 31), |
"05-7-31", "", "2005-7-31", "", "2005年7月31日", "", "2005年7月31日星期日", ""); |
gen4DateFormat(testCases, "en-us", "en_US", new Date(2005, 6, 31), |
"7/31/05", "", "Jul 31, 2005", "", "July 31, 2005", "", "Sunday, July 31, 2005", ""); |
gen4DateFormat(testCases, "fr-fr", "fr_FR", new Date(2005, 6, 31), |
"31/07/05", "", "31 juil. 05", "", "31 juillet 2005", "", "dimanche 31 juillet 2005", ""); |
gen4DateFormat(testCases, "ja-jp", "ja_JP", new Date(2005, 6, 31), |
"05/07/31", "", "2005/07/31", "", "2005年7月31日", "", "2005年7月31日日曜日", ""); |
gen4DateFormat(testCases, "ar-eg", "ar_EG", new Date(2005, 6, 31), |
"31/7/2005", "", "31/07/2005", "", "31 يوليو, 2005", "", "الأحد, 31 يوليو, 2005", ""); |
gen4DateFormat(testCases, "hi-in", "hi_IN", new Date(2005, 6, 31), |
"३१-७-०५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>", "३१-०७-२००५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>", "३१ जुलाई २००५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>", "रविवार ३१ जुलाई २००५", "<a href='currency.html#cmt_3'>See #3 (currency.html).</a>"); |
genValidateTestCases("Date Validate", "dijit.form.DateTextBox", testCases); |
dojo.parser.parse(); |
})(); |
</script> |
</body> |
</html> |
<!-- |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'short', localeDigit: true}" : "{formatLength:'short'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Short</b>", |
value: date, |
expValue: short, |
comment: shortCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'medium', localeDigit: true}" : "{formatLength:'medium'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Medium</b>", |
value: date, |
expValue: medium, |
comment: mediumCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'long', localeDigit: true}" : "{formatLength:'long'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Long</b>", |
value: date, |
expValue: long, |
comment: longCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'full', localeDigit: true}" : "{formatLength:'full'}", lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Full</b>", |
value: date, |
expValue: full, |
comment: fullCmt |
--> |
/trunk/api/js/dojo1.0/dijit/tests/i18n/module.js |
---|
New file |
0,0 → 1,17 |
if(!dojo._hasResource["dijit.tests.i18n.module"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
dojo._hasResource["dijit.tests.i18n.module"] = true; |
dojo.provide("dijit.tests.i18n.module"); |
try{ |
if(dojo.isBrowser){ |
doh.registerUrl("dijit.tests.i18n.currency", dojo.moduleUrl("dijit", "tests/i18n/currency.html")); |
doh.registerUrl("dijit.tests.i18n.date", dojo.moduleUrl("dijit", "tests/i18n/date.html")); |
doh.registerUrl("dijit.tests.i18n.number", dojo.moduleUrl("dijit", "tests/i18n/number.html")); |
doh.registerUrl("dijit.tests.i18n.textbox", dojo.moduleUrl("dijit", "tests/i18n/textbox.html")); |
doh.registerUrl("dijit.tests.i18n.time", dojo.moduleUrl("dijit", "tests/i18n/time.html")); |
} |
}catch(e){ |
doh.debug(e); |
} |
} |
/trunk/api/js/dojo1.0/dijit/tests/i18n/textbox.html |
---|
New file |
0,0 → 1,173 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>Test TextBox</title> |
<script type="text/javascript" src="../../../dojo/dojo.js" |
djConfig="isDebug: true"></script> |
<script type="text/javascript" src="../../../dojo/currency.js"></script> |
<script type="text/javascript" src="../../../dojo/number.js"></script> |
<script type="text/javascript"> |
dojo.require("dijit.form.NumberTextBox"); |
dojo.require("dijit.form.CurrencyTextBox"); |
dojo.require("dijit.form.DateTextBox"); |
dojo.require("dijit.form.ValidationTextBox"); |
dojo.require("dojo.date.locale"); |
dojo.require("dojo.date.stamp"); |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
dojo.require("doh.runner"); |
</script> |
<script src="test_i18n.js"></script> |
<script type="text/javascript"> |
dojo.addOnLoad(function(){ |
doh.register("t", getAllTestCases()); |
doh.run(); |
}); |
</script> |
<style type="text/css"> |
@import "../../../dojo/resources/dojo.css"; |
@import "../../themes/tundra/tundra.css"; |
@import "../css/dijitTests.css"; |
.title { |
background-color:#ddd; |
} |
.hint { |
background-color:#eee; |
} |
.testExample { |
background-color:#fbfbfb; |
padding:1em; |
margin-bottom:1em; |
border:1px solid #bfbfbf; |
} |
.dojoTitlePaneLabel label { |
font-weight:bold; |
} |
td {white-space:nowrap} |
</style> |
</head> |
<body class="tundra"> |
<h1 class="testTitle">Dijit TextBox Globalization Test</h1> |
<!-- <h2 class="testTitle">Press the following button to start all test after this page is loaded.</h2> |
<button id="startButton" onclick="startTest()">Start Test</button>--> |
<script> |
(function() { |
genFormatTestCases("Natural Language Casing Mapping", "dijit.form.TextBox", [ |
{ attrs: {uppercase: "true"}, |
desc: "Upper casing: Basic Latin", |
value: "abcdefghijklmnopqrstuvwxyz", |
expValue: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", |
comment: "" |
}, |
{ attrs: {uppercase: "true"}, |
desc: "Upper casing: Latin with accents", |
value: "àáâãäåæçèéêëìíîïðñòóôõö", |
expValue: "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ", |
comment: "" |
}, |
{ attrs: {uppercase: "true"}, |
desc: "Upper casing: Turkish", |
value: "ıi", |
expValue: "Iİ", |
comment: "<a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {uppercase: "true"}, |
desc: "Upper casing: Russian", |
value: "абвгдежз", |
expValue: "АБВГДЕЖЗ", |
comment: "" |
}, |
{ attrs: {uppercase: "true"}, |
desc: "Upper casing: German", |
value: "ß", |
expValue: "SS", |
comment: "<a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {lowercase: "true"}, |
desc: "Lower casing: Turkish", |
value: "Iİ", |
expValue: "ıi", |
comment: "<a href='#cmt_1'>See #1.</a>" |
}, |
{ attrs: {propercase: "true"}, |
desc: "Title/Proper casing: Latin", |
value: "\u01F1abc", |
expValue: "\u01F2abc", |
comment: "<a href='#cmt_1'>See #1.</a>" |
} |
]); |
genFormatTestCases("White-space Detecting", "dijit.form.TextBox", [ |
{ attrs: {trim: "true"}, |
desc: "Normal space & tab", |
value: " abc\t\t\t", |
expValue: "abc", |
comment: "" |
}, |
{ attrs: {trim: "true"}, |
desc: "NO-BREAK SPACE", |
value: "\u00A0abc\u00A0", |
expValue: "abc", |
comment: "Failed in IE. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {trim: "true"}, |
desc: "EN QUAD", |
value: "\u2000abc\u2000", |
expValue: "abc", |
comment: "Failed in IE. <a href='#cmt_2'>See #2.</a>" |
}, |
{ attrs: {trim: "true"}, |
desc: "IDEOGRAPHIC SPACE", |
value: "\u3000abc\u3000", |
expValue: "abc", |
comment: "Failed in IE. <a href='#cmt_2'>See #2.</a>" |
} |
]); |
dojo.parser.parse(); |
})(); |
</script> |
<h2 class="testTitle">Issues & Comments </h2> |
<a name="cmt_1"><h3 class="testTitle">Issue #1 <sup style="color:red">Not fixed. Avoid using this function of TextBox.</sup></h3></a> |
<p> |
Strictly speaking, all casing manipulation must use ICU case mapping rules (routine). However, the default JavaScript routines used by Dojo |
do not support ICU case mapping rules in all browsers. |
</p> |
<a name="cmt_2"><h3 class="testTitle">Issue #2 <sup style="color:red">Not fixed. Avoid using this function of TextBox.</sup></h3></a> |
<p> |
Trimming must get rid of all Unicode characters with the white space property. However, the default JavaScript routines used by Dojo |
do not support get character properties in some browsers like IE. Other browsers like Firefox might support trimming more white space |
characters. |
</p> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dijit/tests/i18n/time.html |
---|
New file |
0,0 → 1,210 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>Test TextBox for Time</title> |
<script type="text/javascript" src="../../../dojo/dojo.js" |
djConfig="isDebug: true, extraLocale: ['zh-cn','fr-fr','ja-jp','ar-eg','ru-ru','hi-in','en-us']"></script> |
<script type="text/javascript" src="../../../dojo/currency.js"></script> |
<script type="text/javascript" src="../../../dojo/number.js"></script> |
<script type="text/javascript"> |
dojo.require("dijit.form.ValidationTextBox"); |
dojo.require("dojo.date.locale"); |
dojo.require("dojo.date.stamp"); |
dojo.require("dojo.date"); |
dojo.require("dojo.string"); |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
dojo.require("doh.runner"); |
</script> |
<script src="test_i18n.js"></script> |
<script type="text/javascript"> |
dojo.addOnLoad(function(){ |
doh.register("t", getAllTestCases()); |
doh.run(); |
}); |
</script> |
<style type="text/css"> |
@import "../../../dojo/resources/dojo.css"; |
@import "../../themes/tundra/tundra.css"; |
@import "../css/dijitTests.css"; |
.title { |
background-color:#ddd; |
} |
.hint { |
background-color:#eee; |
} |
.testExample { |
background-color:#fbfbfb; |
padding:1em; |
margin-bottom:1em; |
border:1px solid #bfbfbf; |
} |
.dojoTitlePaneLabel label { |
font-weight:bold; |
} |
td {white-space:nowrap} |
</style> |
<script> |
dojo.declare( |
"dijit.form.TimeTextBox", |
dijit.form.ValidationTextBox, |
{ |
regExpGen: dojo.date.locale.regexp, |
format: dojo.date.locale.format, |
parse: dojo.date.locale.parse, |
value: new Date() |
} |
); |
var tz_s = dojo.date.getTimezoneName(new Date()); |
if (!tz_s) { |
var offset = new Date().getTimezoneOffset(); |
var tz = [ |
(offset <= 0 ? "+" : "-"), |
dojo.string.pad(Math.floor(Math.abs(offset) / 60), 2), |
dojo.string.pad(Math.abs(offset) % 60, 2) |
]; |
tz.splice(0, 0, "GMT"); |
tz.splice(3, 0, ":"); |
tz_s = tz.join(""); |
} |
function gen4DateFormat(testCases, language, locale, date, short, shortCmt, medium, mediumCmt, long, longCmt, full, fullCmt) { |
var tz_l = language.indexOf("hi") == 0 && dojo.number.normalizeDigitChars ? |
dojo.number.normalizeDigitChars(tz_s, language) : tz_s; |
short = short.replace(/UTC/, tz_l); |
medium = medium.replace(/UTC/, tz_l); |
long = long.replace(/UTC/g, tz_l); |
full = full.replace(/UTC/, tz_l); |
var shortDate = null; |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'short', selector:'time', localeDigit:true}" : "{formatLength:'short', selector:'time'}", |
lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Short</b>", |
value: typeof(date) == "string" ? date : shortDate = new Date(date.getYear(), date.getMonth(), date.getDay() - 5, date.getHours(), date.getMinutes()), |
expValue: short, |
comment: shortCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'medium', selector:'time', localeDigit:true}" : "{formatLength:'medium', selector:'time'}", |
lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Medium</b>", |
value: date, |
expValue: medium, |
comment: mediumCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'long', selector:'time', localeDigit:true}" : "{formatLength:'long', selector:'time'}", |
lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Long</b>", |
value: date, |
expValue: long, |
comment: longCmt |
}); |
testCases.push({ |
attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'full', selector:'time', localeDigit:true}" : "{formatLength:'full', selector:'time'}", |
lang: language}, |
desc: "Locale: <b>" + locale + "</b> Format: <b>Full</b>", |
value: typeof(date) == "string" || language.indexOf("fr") ? date : shortDate, |
expValue: full, |
comment: fullCmt |
}); |
date.processValue = function (value) { |
return value ? new Date(1970, 0, 1, value.getHours(), value.getMinutes(), value.getSeconds()) : value; |
}; |
if (shortDate) { |
shortDate.processValue = date.processValue; |
} |
} |
</script> |
</head> |
<body class="tundra"> |
<h1 class="testTitle">Dijit TextBox Globalization Test for Time</h1> |
<h2 class="testTitle">Press the following button to start all test after this page is loaded.</h2> |
<button id="startButton" onclick="startTest()">Start Test</button> |
<p> |
Before start this test, make sure the <b>dojo/cldr/nls</b> contains the data for "zh-cn", "fr-fr", "ja-jp", "ru-ru", "hi-in", "en-us" and "ar-eg". If not, convert these CLDR data and put them there. |
</p> |
<script> |
(function() { |
var testCases; |
testCases = new Array(); |
gen4DateFormat(testCases, "ru-ru", "ru_RU", "1970-01-01T15:25:35", |
"15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "zh-cn", "zh_CN", "1970-01-01T15:25:35", |
"下午3:25", "", "下午03:25:35", "", "下午03时25分35秒", "", "下午03时25分35秒 UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "en-us", "en_US", "1970-01-01T15:25:35", |
"3:25 PM", "", "3:25:35 PM", "", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "fr-fr", "fr_FR", "1970-01-01T15:25:35", |
"15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15 h 25 UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "ja-jp", "ja_JP", "1970-01-01T15:25:35", |
"15:25", "", "15:25:35", "", "15:25:35:UTC", "<a href='#cmt_1'>See #1.</a>", "15時25分35秒UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "ar-eg", "ar_EG", "1970-01-01T15:25:35", |
"3:25 \u0645", "", "3:25:35 \u0645", "", "3:25:35 \u0645", "", "UTC 3:25:35 \u0645", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "hi-in", "hi_IN", "1970-01-01T15:25:35", |
"३:२५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>"); |
genFormatTestCases("Time Format", "dijit.form.TimeTextBox", testCases); |
testCases = new Array(); |
gen4DateFormat(testCases, "ru-ru", "ru_RU", new Date(1970, 0, 1, 15, 25, 35), |
"15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "zh-cn", "zh_CN", new Date(1970, 0, 1, 15, 25, 35), |
"下午3:25", "<a href='#cmt_3'>See #3.</a>", "下午03:25:35", "<a href='#cmt_3'>See #3.</a>", "下午03时25分35秒", "<a href='#cmt_3'>See #3.</a>", "下午03时25分35秒 UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "en-us", "en_US", new Date(1970, 0, 1, 15, 25, 35), |
"3:25 PM", "", "3:25:35 PM", "", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "fr-fr", "fr_FR", new Date(1970, 0, 1, 15, 25, 35), |
"15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15 h 25 UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "ja-jp", "ja_JP", new Date(1970, 0, 1, 15, 25, 35), |
"15:25", "", "15:25:35", "", "15:25:35:UTC", "<a href='#cmt_1'>See #1.</a>", "15時25分35秒UTC", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "ar-eg", "ar_EG", new Date(1970, 0, 1, 15, 25, 35), |
"3:25 \u0645", "", "3:25:35 \u0645", "", "3:25:35 \u0645", "", "UTC 3:25:35 \u0645", "<a href='#cmt_1'>See #1.</a>"); |
gen4DateFormat(testCases, "hi-in", "hi_IN", new Date(1970, 0, 1, 15, 25, 35), |
"३:२५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>"); |
genValidateTestCases("Time Validate", "dijit.form.TimeTextBox", testCases); |
dojo.parser.parse(); |
})(); |
</script> |
<h2 class="testTitle">Issues & Comments</h2> |
<a name="cmt_1"><h3 class="testTitle">Issue #1 <sup style="color:blue">Fixed</sup></h3></a> |
<p> |
Currently Dojo do not support parsing for most "long" and "full" time format which have a timezone mark in it. |
</p> |
<a name="cmt_2"><h3 class="testTitle">Issue #2 <sup style="color:blue">Fixed: added a "localeDigit" to the options</sup></h3></a> |
<p> |
Strictly speaking, the data conversion must support non-European number characters in some locales like Arabic and Hindi. |
For example, ICU formats a number data into Indic number characters by default in the Arabic locale. |
However, currently Dojo does not support this feature (Dojo uses the default number conversion of the browser). |
</p> |
<a name="cmt_3"><h3 class="testTitle">Issue #3 <sup style="color:blue">Fixed</sup></h3></a> |
<p> |
This defect only occurs on the "zh-cn" locale. Dojo accepts "下午"(pm) in the textbox, but it automatically changes it to |
"上午"(am) after the focus changed. The date value of the textbox is also changed. |
</p> |
<p> |
The root cause of this issue is that the parser method's code assumes am/pm symbol always appears after the hour value. |
But this is not true, for example, the pattern for "zh-cn" puts am/pm field before all the other fields. |
</p> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dijit/tests/i18n/test_i18n.js |
---|
New file |
0,0 → 1,206 |
var validateValues = []; |
var formatWidgetCount = 0; |
var validateWidgetCount = 0; |
function getElementsById(id){ |
var result = []; |
if(!id || typeof(id) != "string"){ |
return result; |
} |
var ae = document.getElementsByTagName(dojo.byId(id).tagName); |
for(var i = 0; i < ae.length; i++){ |
if(ae[i].id == id){ |
result.push(ae[i]); |
} |
} |
return result; |
} |
function getString(n){ |
return n && n.toString(); |
} |
function startTest(t){ |
startTestFormat(t); |
startTestValidate(t); |
} |
function escapeEx(s){ |
var result = ""; |
for(var i = 0; i < s.length; i++){ |
var c = s.charAt(i); |
switch (c){ |
case '"': |
result += '\\"'; |
break; |
case "'": |
result += "\\'"; |
break; |
default: |
result += escape(c); |
break; |
} |
} |
return result; |
} |
function getAllTestCases(){ |
var allTestCases = []; |
for(var i = 0; i < formatWidgetCount; i++){ |
allTestCases.push({ |
name: "format-" + i, |
runTest: new Function("t", "startTestFormat(" + i + ", t)") |
}); |
} |
for(var i = 0; i < validateWidgetCount; i++){ |
allTestCases.push({ |
name: "validate-" + i, |
runTest: new Function("t", "startTestValidate(" + i + ", t)") |
}); |
} |
return allTestCases; |
} |
function startTestFormat(i, t){ |
var test_node = dojo.doc.getElementById("test_display_" + i); |
var exp = dojo.doc.getElementById("test_display_expected_" + i).value; |
var res_node = dojo.doc.getElementById("test_display_result_" + i); |
res_node.innerHTML = test_node.value; |
res_node.style.backgroundColor = (test_node.value == exp) ? "#AFA" : "#FAA"; |
res_node.innerHTML += " <a style='font-size:0.8em' href='javascript:alert(\"Expected: " + escapeEx(exp) + "\\n Result: " + escapeEx(test_node.value) + "\")'>Compare (Escaped)</a>"; |
t.is(exp, test_node.value); |
} |
function startTestValidate(i, t){ |
/* |
* The dijit.byNode has an issue: cannot handle same id. |
*/ |
var test_node = dojo.doc.getElementById("test_validate_" + i); |
var inp_node = dojo.doc.getElementById("test_validate_input_" + i); |
var exp = dojo.doc.getElementById("test_validate_expected_" + i).innerHTML; |
var res_node = dojo.doc.getElementById("test_validate_result_" + i); |
var val_node = dojo.doc.getElementById("test_display_value_" + i); |
test_node.value = inp_node.value; |
/* |
* The dijit.byNode has an issue. |
*/ |
var widget = null; |
var node = test_node; |
while ((widget = dijit.byNode(node)) == null){ |
node = node.parentNode; |
if(!node){ |
break; |
} |
} |
if(widget){ |
widget.focus(); |
var expected = validateValues[i]; |
var result = widget.getValue(); |
if(validateValues[i].processValue){ |
expected = validateValues[i].processValue(expected); |
result = validateValues[i].processValue(result); |
} |
var parseCorrect = getString(expected) == getString(result); |
val_node.style.backgroundColor = parseCorrect ? "#AFA" : "#FAA"; |
val_node.innerHTML = getString(result) + (parseCorrect ? "" : "<br>Expected: " + getString(expected)); |
res_node.innerHTML = widget.isValid && !widget.isValid() ? "Wrong" : "Correct"; |
res_node.style.backgroundColor = res_node.innerHTML == exp ? "#AFA" : "#FAA"; |
t.is(getString(expected), getString(result)); |
} |
} |
function genFormatTestCase(desc, dojoType, dojoAttrs, value, expValue, comment){ |
dojo.doc.write("<tr>"); |
dojo.doc.write("<td>" + desc + "</td>"); |
dojo.doc.write("<td>"); |
dojo.doc.write("<input id='test_display_" + formatWidgetCount + "' type='text' value='" + value + "' "); |
dojo.doc.write("dojoType='" + dojoType + "' "); |
for(var attr in dojoAttrs){ |
dojo.doc.write(attr + "=\"" + dojoAttrs[attr] + "\" "); |
} |
dojo.doc.write("/>"); |
dojo.doc.write("</td>"); |
dojo.doc.write("<td><input id='test_display_expected_" + formatWidgetCount + "' value='" + expValue + "'></td>"); |
dojo.doc.write("<td id='test_display_result_" + formatWidgetCount + "'></td>"); |
dojo.doc.write("<td style='white-space:normal'>" + comment + "</td>"); |
dojo.doc.write("</tr>"); |
formatWidgetCount++; |
} |
/* |
[ |
{attrs: {currency: "CNY", lang: "zh-cn"}, desc: "", value:"-123456789.46", expValue: "", comment: ""}, |
... |
] |
*/ |
function genFormatTestCases(title, dojoType, testCases){ |
dojo.doc.write("<h2 class=testTitle>" + title + "</h2>"); |
dojo.doc.write("<table border=1>"); |
dojo.doc.write("<tr>"); |
dojo.doc.write("<td class=title><b>Test Description</b></td>"); |
dojo.doc.write("<td class=title><b>Test</b></td>"); |
dojo.doc.write("<td class=title><b>Expected</b></td>"); |
dojo.doc.write("<td class=title><b>Result</b></td>"); |
dojo.doc.write("<td class=title><b>Comment</b></td>"); |
dojo.doc.write("</tr>"); |
for(var i = 0; i < testCases.length; i++){ |
var testCase = testCases[i]; |
genFormatTestCase(testCase.desc, dojoType, testCase.attrs, testCase.value, testCase.expValue, testCase.comment); |
} |
dojo.doc.write("</table>"); |
} |
function genValidateTestCase(desc, dojoType, dojoAttrs, input, value, comment, isWrong){ |
dojo.doc.write("<tr>"); |
dojo.doc.write("<td>" + desc + "</td>"); |
dojo.doc.write("<td>"); |
dojo.doc.write("<input id='test_validate_" + validateWidgetCount + "' type='text' "); |
dojo.doc.write("dojoType='" + dojoType + "' "); |
for(var attr in dojoAttrs){ |
dojo.doc.write(attr + "=\"" + dojoAttrs[attr] + "\" "); |
} |
dojo.doc.write("/>"); |
dojo.doc.write("</td>"); |
dojo.doc.write("<td><input id='test_validate_input_" + validateWidgetCount + "' value='" + input + "'></td>"); |
dojo.doc.write("<td id='test_display_value_" + validateWidgetCount + "'></td>"); |
dojo.doc.write("<td id='test_validate_expected_" + validateWidgetCount + "'>" + (isWrong ? "Wrong" : "Correct") + "</td>"); |
dojo.doc.write("<td id='test_validate_result_" + validateWidgetCount + "'></td>"); |
dojo.doc.write("<td style='white-space:normal'>" + comment + "</td>"); |
dojo.doc.write("</tr>"); |
validateValues.push(value); |
validateWidgetCount++; |
} |
/* |
[ |
{attrs: {currency: "CNY", lang: "zh-cn"}, desc: "", value:false, expValue: "-123456789.46", comment: ""}, |
... |
] |
*/ |
function genValidateTestCases(title, dojoType, testCases){ |
dojo.doc.write("<h2 class=testTitle>" + title + "</h2>"); |
dojo.doc.write("<table border=1>"); |
dojo.doc.write("<tr>"); |
dojo.doc.write("<td class=title><b>Test Description</b></td>"); |
dojo.doc.write("<td class=title><b>Test</b></td>"); |
dojo.doc.write("<td class=title><b>Input</b></td>"); |
dojo.doc.write("<td class=title><b>Parsed Value</b></td>"); |
dojo.doc.write("<td class=title><b>Expected</b></td>"); |
dojo.doc.write("<td class=title><b>Result</b></td>"); |
dojo.doc.write("<td class=title><b>Comment</b></td>"); |
dojo.doc.write("</tr>"); |
for(var i = 0; i < testCases.length; i++){ |
var testCase = testCases[i]; |
genValidateTestCase(testCase.desc, dojoType, testCase.attrs, testCase.expValue, testCase.value, testCase.comment, testCase.isWrong); |
} |
dojo.doc.write("</table>"); |
} |