Skip to content

Commit

Permalink
Fix delimeters for the enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecimovic committed Aug 17, 2020
1 parent f13c67e commit 3098449
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src-electron/generator/helper-c.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function asMacro(label) {
return l
}

function isDigit(ch) {
return ch >= '0' && ch <= '9'
}

/**
* Takes a label, and delimits is on camelcasing.
* For example:
Expand All @@ -52,16 +56,22 @@ function asDelimitedMacro(label) {
var ret = ''
if (label == null) return ret

var wasUp = false
for (var i = 0; i < label.length; i++) {
var ch = label.charAt(i)
var upch = ch.toUpperCase()
if (ch == upch) {
if (ch == '_') {
ret = ret.concat('_')
wasUp = true
} else if (ch == upch) {
// uppercase
if (i != 0) ret = ret.concat('_')
ret = ret.concat(ch.toUpperCase())
if (i != 0 && !wasUp) ret = ret.concat('_')
ret = ret.concat(upch)
wasUp = true
} else {
// lowercase
ret = ret.concat(upch)
wasUp = false
}
}
return ret
Expand Down
2 changes: 1 addition & 1 deletion src-electron/main-process/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function startGeneration(
output,
{
log: options.log,
backup: true,
backup: false,
}
)
)
Expand Down
16 changes: 10 additions & 6 deletions test/gen-template/zap-type.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ enum {
};

// ZCL attribute sizes
enum {
#define ZAP_GENERATED_ATTRIBUTE_SIZES { \
{{#zcl_atomics}}
{{#if size}}
{{ident}}ZCL_{{asMacro name}}_ATTRIBUTE_SIZE = {{size}}, // {{description}}
{{ident}}ZCL_{{asMacro name}}_ATTRIBUTE_TYPE, {{size}}, \
{{/if}}
{{/zcl_atomics}}
};
}

// ZCL enums

Expand All @@ -23,11 +23,13 @@ enum {
// Enum for {{label}}
typedef enum {
{{#zcl_enum_items}}
{{ident}}ZCL_{{asMacro parent.label}}_{{asMacro label}} {{value}},
{{ident}}EMBER_ZCL_{{asDelimitedMacro parent.label}}_{{asDelimitedMacro label}} = {{value}},
{{/zcl_enum_items}}
} {{asType label}};
} EmberAf{{asType label}};
{{/zcl_enums}}

/* COMMENT ALL THIS OUT TEMPORARILY

// ZCL Structs

{{#zcl_structs}}
Expand All @@ -38,4 +40,6 @@ typedef struct _{{asType label}} {
{{ident}}{{asType type}} {{asSymbol label}};
{{/zcl_struct_items}}
} {{asType label}};
{{/zcl_structs}}
{{/zcl_structs}}

*/
8 changes: 8 additions & 0 deletions test/templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @jest-environment node
*/
const handlebars = require('handlebars')
const helperC = require('../src-electron/generator/helper-c.js')

test('handlebars: simple test', () => {
var template = handlebars.compile('{{a}} {{b}} {{c}}!')
Expand Down Expand Up @@ -128,3 +129,10 @@ test('handlebars: iterator', () => {
var output = template({ prefix: 'PRE:', postfix: ':ERP' })
expect(output).toEqual('PRE:0123456789:ERP')
})

test('delimeter macros', () => {
expect(helperC.asDelimitedMacro('VerySimple')).toEqual('VERY_SIMPLE')
expect(helperC.asDelimitedMacro('Very_simple')).toEqual('VERY_SIMPLE')
expect(helperC.asDelimitedMacro('Very_Simple')).toEqual('VERY_SIMPLE')
expect(helperC.asDelimitedMacro('Very_123_Simple')).toEqual('VERY_123_SIMPLE')
})

0 comments on commit 3098449

Please sign in to comment.