Skip to content

Commit

Permalink
Thread annotations for individual enum definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Oct 18, 2016
1 parent ab3b3c4 commit 847ca65
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function ThriftEnum() {
this.valuesToNames = Object.create(null);
// "Interned" names
this.namesToNames = Object.create(null);
this.namesToAnnotations = Object.create(null);
this.surface = this.namesToNames;
this.annotations = null;
this.rw = new EnumRW(this);
Expand Down Expand Up @@ -76,6 +77,7 @@ ThriftEnum.prototype.compile = function compile(def, model) {
this.namesToValues[name] = value;
this.namesToNames[name] = name;
this.valuesToNames[value] = name;
this.namesToAnnotations[name] = enumDef.annotations;
value++;
}

Expand Down
7 changes: 7 additions & 0 deletions test/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ tape('parse enum.thrift', function t(assert) {
assert.end();
});

tape('can access enum def annotations', function t(assert) {
var MAE = thrift.models.MyAnnotatedEnum;
assert.deepEqual(MAE.annotations, {'aka': 'my.annotated.enum'});
assert.deepEqual(MAE.namesToAnnotations.MAE_A, {'aka': 'my.annotated.enum.a'});
assert.end();
});

tape('round trip an enum', function t(assert) {
var inStruct = {me2_2: 'ME2_2', me3_n2: 'ME3_N2', me3_d1: 'ME3_D1'};
var buffer = MyStruct.toBuffer(inStruct);
Expand Down
4 changes: 4 additions & 0 deletions test/enum.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ enum MyEnum4 {
// represented with an i32.
}

enum MyAnnotatedEnum {
MAE_A (aka = "my.annotated.enum.a")
} (aka = "my.annotated.enum")

struct MyStruct {
1: MyEnum2 me2_2 = MyEnum2.ME2_2
2: MyEnum3 me3_n2 = MyEnum3.ME3_N2
Expand Down

0 comments on commit 847ca65

Please sign in to comment.