Files
sdk/pkg/polymer/test/build/utils_test.dart
T
jmesserly@google.com cf3dcfba4c Port Polymer.js Core, the github.com/polymer/polymer code.
Ports all features except where JS interop is blocking us (declaration/path.js and instance/style.js). In particular, this has:
  //   src/declaration/attributes.js
  //   src/declaration/events.js
  //   src/declaration/polymer-element.js
  //   src/declaration/properties.js
  //   src/declaration/prototype.js
  //   src/declaration/styles.js
  //   src/instance/attributes.js
  //   src/instance/base.js
  //   src/instance/events.js
  //   src/instance/mdv.js
  //   src/instance/properties.js
  //   src/instance/utils.js
  //   src/lib/deserialize.js
  //   src/lib/job.js
  //   src/lib/dom.js -- not needed in Dart
  //   src/lib/lang.js -- not needed in Dart
  //   src/lib/super.js -- not needed in Dart

There's also a big architectural change: polymer-element data is now stored in the PolymerDeclaration class, which is separate from PolymerElement. This allows us to avoid duplicate work on every constructor, and should significantly speed up instance creation.

All code is from the same revision:
https://github.com/Polymer/polymer/blob/4dc481c11505991a7c43228d3797d28f21267779

The remaining unported files are for relatively minor features. "declaration/path.js" is for asset URL resolution, and we might have a Pub-based solution instead. "instance/style.js" has an opt-in, advanced style polyfill. It needs "ShadowCSS.shimPolyfillDirectives", and probably isn't too hard to make work in a follow up change.

Other changes:
* attributeChanged lifecycle method is implemented.
* ObservableAnnotation is public so Polymer's @published can subclass it
* bindProperty renamed to onPropertyChange to avoid conflict with Polymer member of the same name.
* polymer/lib/boot.js preload's polymer-element and link[rel=stylesheet]

R=blois@google.com

Review URL: https://codereview.chromium.org//24149003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@28134 260f80e4-7a28-3924-810f-c04153c831b5
2013-10-01 23:45:37 +00:00

87 lines
2.8 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/** Tests for some of the utility helper functions used by the compiler. */
library polymer.test.utils_test;
import 'package:unittest/compact_vm_config.dart';
import 'package:unittest/unittest.dart';
import 'package:polymer/src/build/utils.dart';
main() {
useCompactVMConfiguration();
for (bool startUppercase in [false, true]) {
Matcher caseEquals(String str) {
if (startUppercase) str = str[0].toUpperCase() + str.substring(1);
return equals(str);
}
camelCase(str) => toCamelCase(str, startUppercase: startUppercase);
group('toCamelCase startUppercase=$startUppercase', () {
test('empty', () {
expect(camelCase(''), equals(''));
});
test('single token', () {
expect(camelCase('a'), caseEquals('a'));
expect(camelCase('ab'), caseEquals('ab'));
expect(camelCase('Ab'), caseEquals('Ab'));
expect(camelCase('AB'), caseEquals('AB'));
expect(camelCase('long_word'), caseEquals('long_word'));
});
test('dashes in the middle', () {
expect(camelCase('a-b'), caseEquals('aB'));
expect(camelCase('a-B'), caseEquals('aB'));
expect(camelCase('A-b'), caseEquals('AB'));
expect(camelCase('long-word'), caseEquals('longWord'));
});
test('leading/trailing dashes', () {
expect(camelCase('-hi'), caseEquals('Hi'));
expect(camelCase('hi-'), caseEquals('hi'));
expect(camelCase('hi-friend-'), caseEquals('hiFriend'));
});
test('consecutive dashes', () {
expect(camelCase('--hi-friend'), caseEquals('HiFriend'));
expect(camelCase('hi--friend'), caseEquals('hiFriend'));
expect(camelCase('hi-friend--'), caseEquals('hiFriend'));
});
});
}
group('toHyphenedName', () {
test('empty', () {
expect(toHyphenedName(''), '');
});
test('all lower case', () {
expect(toHyphenedName('a'), 'a');
expect(toHyphenedName('a-b'), 'a-b');
expect(toHyphenedName('aBc'), 'a-bc');
expect(toHyphenedName('abC'), 'ab-c');
expect(toHyphenedName('abc-d'), 'abc-d');
expect(toHyphenedName('long_word'), 'long_word');
});
test('capitalized letters in the middle/end', () {
expect(toHyphenedName('aB'), 'a-b');
expect(toHyphenedName('longWord'), 'long-word');
});
test('leading capital letters', () {
expect(toHyphenedName('Hi'), 'hi');
expect(toHyphenedName('Hi-'), 'hi-');
expect(toHyphenedName('HiFriend'), 'hi-friend');
});
test('consecutive capital letters', () {
expect(toHyphenedName('aBC'), 'a-b-c');
});
});
}