| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('total_tests'); | 5 #library('total_tests'); |
| 6 | 6 |
| 7 #import('../../../../base/base.dart'); | 7 #import('../../../../base/base.dart'); |
| 8 #import('dart:html'); | 8 #import('dart:html'); |
| 9 #import('../../../../samples/total/src/TotalLib.dart'); | 9 #import('../../../../samples/total/src/TotalLib.dart'); |
| 10 #import('../../../../testing/unittest/unittest.dart'); | 10 #import('../../../../testing/unittest/unittest.dart'); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 _checkDate('07-07-2011', 40731.0); | 43 _checkDate('07-07-2011', 40731.0); |
| 44 _checkDate('07-7-2011', 40731.0); | 44 _checkDate('07-7-2011', 40731.0); |
| 45 | 45 |
| 46 // Test MM-DD-<current year> | 46 // Test MM-DD-<current year> |
| 47 double date = DateUtils.parseDate('7/7'); | 47 double date = DateUtils.parseDate('7/7'); |
| 48 double years = (date - 40731.0) / 365.0; | 48 double years = (date - 40731.0) / 365.0; |
| 49 // Assert days/365 is close to an integer -- this will be true for > 100 yea
rs | 49 // Assert days/365 is close to an integer -- this will be true for > 100 yea
rs |
| 50 Expect.isTrue(years - years.floor() < 0.1, "7/7"); | 50 Expect.isTrue(years - years.floor() < 0.1, "7/7"); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 test('HtmlUtils', () { | 53 asyncTest('HtmlUtils', 1, () { |
| 54 Expect.equals("", HtmlUtils.quoteHtml("")); | 54 Expect.equals("", HtmlUtils.quoteHtml("")); |
| 55 Expect.equals("<", HtmlUtils.quoteHtml("<")); | 55 Expect.equals("<", HtmlUtils.quoteHtml("<")); |
| 56 Expect.equals("<<<<", HtmlUtils.quoteHtml("<<<<")); | 56 Expect.equals("<<<<", HtmlUtils.quoteHtml("<<<<")); |
| 57 Expect.equals("Hello<World", HtmlUtils.quoteHtml("Hello<World")); | 57 Expect.equals("Hello<World", HtmlUtils.quoteHtml("Hello<World")); |
| 58 Expect.equals("Hello<<World", HtmlUtils.quoteHtml("Hello<<World")); | 58 Expect.equals("Hello<<World", HtmlUtils.quoteHtml("Hello<<World")); |
| 59 Expect.equals("Hello<W<orld", HtmlUtils.quoteHtml("Hello<W<orld")); | 59 Expect.equals("Hello<W<orld", HtmlUtils.quoteHtml("Hello<W<orld")); |
| 60 Expect.equals("<Hello<World", HtmlUtils.quoteHtml("<Hello<World")); | 60 Expect.equals("<Hello<World", HtmlUtils.quoteHtml("<Hello<World")); |
| 61 Expect.equals("<<Hello<World<", HtmlUtils.quoteHtml("<<Hello<Wor
ld<")); | 61 Expect.equals("<<Hello<World<", HtmlUtils.quoteHtml("<<Hello<Wor
ld<")); |
| 62 Expect.equals("<<Hello<W<orld<", HtmlUtils.quoteHtml("<<Hello
<W<orld<")); | 62 Expect.equals("<<Hello<W<orld<", HtmlUtils.quoteHtml("<<Hello
<W<orld<")); |
| 63 | 63 |
| 64 Document doc = window.document; | 64 Document doc = window.document; |
| 65 Element body = doc.body; | 65 Element body = doc.body; |
| 66 DivElement div = doc.createElement('div'); | 66 DivElement div = doc.createElement('div'); |
| 67 body.nodes.add(div); | 67 body.nodes.add(div); |
| 68 | 68 |
| 69 HtmlUtils.setIntegerProperty(div, "left", 100, "px"); | 69 HtmlUtils.setIntegerProperty(div, "left", 100, "px"); |
| 70 CSSStyleDeclaration computedStyle = window.getComputedStyle(div, ""); | 70 div.computedStyle.then((CSSStyleDeclaration computedStyle) { |
| 71 String valueAsString = computedStyle.getPropertyValue("left"); | 71 String valueAsString = computedStyle.getPropertyValue("left"); |
| 72 // FIXME: Test fails, with valueAsString == "auto". However, setIntegerPrope
rty | 72 // FIXME: Test fails, with valueAsString == "auto". However, |
| 73 // works when tested in practice, so there is something wrong with recoverin
g | 73 // setIntegerProperty works when tested in practice, so there is |
| 74 // the value. | 74 // something wrong with recovering the value. |
| 75 // Expect.equals("100", valueAsString); | 75 // Expect.equals("100", valueAsString); |
| 76 | 76 |
| 77 div.remove(); | 77 div.remove(); |
| 78 callbackDone(); |
| 79 }); |
| 78 }); | 80 }); |
| 79 | 81 |
| 80 test('StringUtils', () { | 82 test('StringUtils', () { |
| 81 _assertNumeric("0"); | 83 _assertNumeric("0"); |
| 82 _assertNumeric(".0"); | 84 _assertNumeric(".0"); |
| 83 _assertNumeric("0.0"); | 85 _assertNumeric("0.0"); |
| 84 _assertNumeric(".1"); | 86 _assertNumeric(".1"); |
| 85 _assertNumeric("1."); | 87 _assertNumeric("1."); |
| 86 _assertNumeric("1.0"); | 88 _assertNumeric("1.0"); |
| 87 _assertNumeric("1e17"); | 89 _assertNumeric("1e17"); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 Expect.isFalse(DateUtils.isDate(date), "DateUtils.isDate(${date})"); | 444 Expect.isFalse(DateUtils.isDate(date), "DateUtils.isDate(${date})"); |
| 443 } | 445 } |
| 444 | 446 |
| 445 _assertNumeric(String s) { | 447 _assertNumeric(String s) { |
| 446 Expect.isTrue(StringUtils.isNumeric(s), 'StringUtils.isNumeric("{$s}")'); | 448 Expect.isTrue(StringUtils.isNumeric(s), 'StringUtils.isNumeric("{$s}")'); |
| 447 } | 449 } |
| 448 | 450 |
| 449 _assertNonNumeric(String s) { | 451 _assertNonNumeric(String s) { |
| 450 Expect.isFalse(StringUtils.isNumeric(s), '!StringUtils.isNumeric("${s}")'); | 452 Expect.isFalse(StringUtils.isNumeric(s), '!StringUtils.isNumeric("${s}")'); |
| 451 } | 453 } |
| OLD | NEW |