Skip to content

Commit

Permalink
Add test for string member of dictionaries (#225)
Browse files Browse the repository at this point in the history
When dictionary has string member, "std::" was missed in front of string
keyword. So, it makes build error.

ISSUE=#169
  • Loading branch information
hwanseung authored and romandev committed Jan 3, 2018
1 parent 70ded6c commit cca347a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions template/dictionary_types.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{%- macro printType(type) -%}
{%- if type == 'string' -%}
std::{{type}}
{%- else -%}
{{type}}
{%- endif -%}
{%- endmacro -%}

/**
* Copyright (c) 2017 The Bacardi Authors.
*
Expand All @@ -20,16 +28,16 @@
class {{name}} {
public:
{% for member in members %}
{{member.type}} {{member.name}}() const {
{{printType(member.type)}} {{member.name}}() const {
return {{member.name}}_;
}
void set{{member.name | pascalcase}}({{member.type}} {{member.name}}) {
void set{{member.name | pascalcase}}({{printType(member.type)}} {{member.name}}) {
{{member.name}}_ = {{member.name}};
}
{% endfor %}
private:
{% for member in members %}
{{member.type}} {{member.name}}_;
{{printType(member.type)}} {{member.name}}_;
{% endfor %}
};

Expand Down
4 changes: 2 additions & 2 deletions test/interface_dictionary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ test(
async () => {
let test_interface = new bacardi.TestInterface();

var testDict = {a: 10};
var testDict = {a: 10, b: "test"};
expect(test_interface.doubleMethodTestDictionaryArg(testDict)).toBe(10);
expect(bacardi.TestInterface.getLastCallInfo())
.toBe('DoubleMethodTestDictionaryArg()');
.toBe('DoubleMethodTestDictionaryArg() : test');
});
2 changes: 1 addition & 1 deletion test/test_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ void TestInterface::SetStaticDoubleNumber(double number) {
}

double TestInterface::DoubleMethodTestDictionaryArg(TestDict testDict) {
last_call_info_ = "DoubleMethodTestDictionaryArg()";
last_call_info_ = "DoubleMethodTestDictionaryArg() : " + testDict.b();
return testDict.a();
}
1 change: 1 addition & 0 deletions test/test_interface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ enum TestEnum {

dictionary TestDict {
double a;
string b;
};

0 comments on commit cca347a

Please sign in to comment.