-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Medium/nick-camel
Tweak how we handle casing
- Loading branch information
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
/** | ||
* @fileoverview Tests casing rulesthat parsing works end-to-end. | ||
*/ | ||
|
||
var fs = require('fs') | ||
var parser = require('../lib/parser') | ||
var path = require('path') | ||
|
||
|
||
exports.testCasingMessage = function (test) { | ||
var proto = parseFile('conventions.proto') | ||
|
||
test.equal(proto.getPackage(), 'conventions') | ||
|
||
var msg = proto.getMessage('Casing') | ||
|
||
test.ok(msg.getField('normal_case')) | ||
test.equal('normal_case', msg.getField('normal_case').toTemplateObject().name) | ||
test.equal('NormalCase', msg.getField('normal_case').toTemplateObject().titleName) | ||
|
||
test.ok(msg.getField('normal_case_ios')) | ||
test.equal('normal_case_ios', msg.getField('normal_case_ios').toTemplateObject().name) | ||
test.equal('NormalCaseIos', msg.getField('normal_case_ios').toTemplateObject().titleName) | ||
|
||
test.ok(msg.getField('camelCase')) | ||
test.equal('camelCase', msg.getField('camelCase').toTemplateObject().name) | ||
test.equal('CamelCase', msg.getField('camelCase').toTemplateObject().titleName) | ||
|
||
test.ok(msg.getField('camelCaseIOS')) | ||
test.equal('camelCaseIOS', msg.getField('camelCaseIOS').toTemplateObject().name) | ||
test.equal('CamelCaseIOS', msg.getField('camelCaseIOS').toTemplateObject().titleName) | ||
|
||
test.ok(msg.getField('TitleCase')) | ||
test.ok(msg.getField('TitleCaseIOS')) | ||
test.ok(msg.getField('Weird_Case')) | ||
|
||
test.done() | ||
} | ||
|
||
exports.testCasingEnum = function (test) { | ||
var proto = parseFile('conventions.proto') | ||
|
||
test.equal(proto.getPackage(), 'conventions') | ||
|
||
var e = proto.getEnum('CasingEnum') | ||
test.equal('TWO_WORDS', e.getValueForNumber(1).name) | ||
test.equal('TwoWords', e.getValueForNumber(1).titleName) | ||
test.done() | ||
} | ||
|
||
function parseFile(file) { | ||
return parser(file, fs.readFileSync(path.join(__dirname, 'protos', file), 'utf8')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
package conventions; | ||
|
||
message Casing { | ||
optional string normal_case = 1; | ||
optional string normal_case_ios = 2; | ||
optional string camelCase = 3; | ||
optional string camelCaseIOS = 4; | ||
optional string TitleCase = 5; | ||
optional string TitleCaseIOS = 6; | ||
optional string Weird_Case = 7; | ||
} | ||
|
||
enum CasingEnum { | ||
TWO_WORDS = 1; | ||
} |