Skip to content

Commit

Permalink
[CLEANUP canary] Refactor string classifier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skeate committed Sep 29, 2015
1 parent 85d725c commit 9f0f28d
Showing 1 changed file with 23 additions and 103 deletions.
126 changes: 23 additions & 103 deletions packages/ember-runtime/tests/system/string/classify_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,107 +9,27 @@ if (!Ember.EXTEND_PROTOTYPES && !Ember.EXTEND_PROTOTYPES.String) {
});
}

QUnit.test('classify normal string', function() {
deepEqual(classify('my favorite items'), 'MyFavoriteItems');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('my favorite items'.classify(), 'MyFavoriteItems');
}
});

QUnit.test('classify dasherized string', function() {
deepEqual(classify('css-class-name'), 'CssClassName');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('css-class-name'.classify(), 'CssClassName');
}
});

QUnit.test('classify underscored string', function() {
deepEqual(classify('action_name'), 'ActionName');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('action_name'.classify(), 'ActionName');
}
});

QUnit.test('does nothing with classified string', function() {
deepEqual(classify('InnerHTML'), 'InnerHTML');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('InnerHTML'.classify(), 'InnerHTML');
}
});

QUnit.test('classify namespaced camelized string', function() {
deepEqual(classify('privateDocs/ownerInvoice'), 'PrivateDocs/OwnerInvoice');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('privateDocs/ownerInvoice'.classify(), 'PrivateDocs/OwnerInvoice');
}
});

QUnit.test('classify namespaced underscored string', function() {
deepEqual(classify('private_docs/owner_invoice'), 'PrivateDocs/OwnerInvoice');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('private_docs/owner_invoice'.classify(), 'PrivateDocs/OwnerInvoice');
}
});

QUnit.test('classify namespaced dasherized string', function() {
deepEqual(classify('private-docs/owner-invoice'), 'PrivateDocs/OwnerInvoice');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('private-docs/owner-invoice'.classify(), 'PrivateDocs/OwnerInvoice');
}
});

QUnit.test('classify prefixed dasherized string', function() {
deepEqual(classify('-view-registry'), '_ViewRegistry');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('-view-registry'.classify(), '_ViewRegistry');
}
});

QUnit.test('classify namespaced prefixed dasherized string', function() {
deepEqual(classify('components/-text-field'), 'Components/_TextField');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('components/-text-field'.classify(), 'Components/_TextField');
}
});

QUnit.test('does nothing with classified prefixed string', function() {
deepEqual(classify('_FooBar'), '_FooBar');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('_FooBar'.classify(), '_FooBar');
}
});

QUnit.test('classify underscore-prefixed underscored string', function() {
deepEqual(classify('_Foo_Bar'), '_FooBar');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('_Foo_Bar'.classify(), '_FooBar');
}
});

QUnit.test('classify underscore-prefixed dasherized string', function() {
deepEqual(classify('_Foo-Bar'), '_FooBar');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('_Foo-Bar'.classify(), '_FooBar');
}
});

QUnit.test('classify underscore-prefixed-namespaced underscore-prefixed string', function() {
deepEqual(classify('_foo/_bar'), '_Foo/_Bar');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('_foo/_bar'.classify(), '_Foo/_Bar');
}
});

QUnit.test('classify dash-prefixed-namespaced underscore-prefixed string', function() {
deepEqual(classify('-foo/_bar'), '_Foo/_Bar');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('-foo/_bar'.classify(), '_Foo/_Bar');
}
});
function test(given, expected, description) {
QUnit.test(description, function() {
deepEqual(classify(given), expected);
if (Ember.EXTEND_PROTOTYPES) {
deepEqual(given.classify(), expected);
}
});
}

QUnit.test('classify dash-prefixed-namespaced dash-prefixed string', function() {
deepEqual(classify('-foo/-bar'), '_Foo/_Bar');
if (Ember.EXTEND_PROTOTYPES) {
deepEqual('-foo/-bar'.classify(), '_Foo/_Bar');
}
});
test('my favorite items', 'MyFavoriteItems', 'classify normal string');
test('css-class-name', 'CssClassName', 'classify dasherized string');
test('action_name', 'ActionName', 'classify underscored string');
test('privateDocs/ownerInvoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced camelized string');
test('private_docs/owner_invoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced underscored string');
test('private-docs/owner-invoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced dasherized string');
test('-view-registry', '_ViewRegistry', 'classify prefixed dasherized string');
test('components/-text-field', 'Components/_TextField', 'classify namespaced prefixed dasherized string');
test('_Foo_Bar', '_FooBar', 'classify underscore-prefixed underscored string');
test('_Foo-Bar', '_FooBar', 'classify underscore-prefixed dasherized string');
test('_foo/_bar', '_Foo/_Bar', 'classify underscore-prefixed-namespaced underscore-prefixed string');
test('-foo/_bar', '_Foo/_Bar', 'classify dash-prefixed-namespaced underscore-prefixed string');
test('-foo/-bar', '_Foo/_Bar', 'classify dash-prefixed-namespaced dash-prefixed string');
test('InnerHTML', 'InnerHTML', 'does nothing with classified string');
test('_FooBar', '_FooBar', 'does nothing with classified prefixed string');

0 comments on commit 9f0f28d

Please sign in to comment.