diff --git a/src-electron/generator/helper-c.js b/src-electron/generator/helper-c.js index bdca1e756be8cc..38ccfeb88e4c4e 100644 --- a/src-electron/generator/helper-c.js +++ b/src-electron/generator/helper-c.js @@ -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: @@ -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 diff --git a/src-electron/main-process/startup.js b/src-electron/main-process/startup.js index b71b9270465bbd..15bb04646d0b79 100644 --- a/src-electron/main-process/startup.js +++ b/src-electron/main-process/startup.js @@ -215,7 +215,7 @@ function startGeneration( output, { log: options.log, - backup: true, + backup: false, } ) ) diff --git a/test/gen-template/zap-type.zapt b/test/gen-template/zap-type.zapt index 98f26edd079c24..686103f1795fa2 100644 --- a/test/gen-template/zap-type.zapt +++ b/test/gen-template/zap-type.zapt @@ -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 @@ -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}} @@ -38,4 +40,6 @@ typedef struct _{{asType label}} { {{ident}}{{asType type}} {{asSymbol label}}; {{/zcl_struct_items}} } {{asType label}}; -{{/zcl_structs}} \ No newline at end of file +{{/zcl_structs}} + +*/ \ No newline at end of file diff --git a/test/templates.test.js b/test/templates.test.js index eb49e1243a86fd..7eef7dfcfa6391 100644 --- a/test/templates.test.js +++ b/test/templates.test.js @@ -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}}!') @@ -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') +})