-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize case handling for objects and callbacks
Objects and callbacks were not handling case consistently in generated across code, leading to compilation errors in some cases (see #22). The main problem arises in capital acronym handling, i.e. `HTTPClient`. Such acronyms are converted using `heck::to_upper_camel_case`, which converts upper case acronym `HTTP` into upper camel case `Http`, i.e. `HttpClient`.
- Loading branch information
Showing
14 changed files
with
177 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,30 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package binding_tests | ||
|
||
import ( | ||
"errors" | ||
. "github.com/NordSecurity/uniffi-bindgen-go/binding_tests/generated/name_case" | ||
"testing" | ||
) | ||
|
||
type MyNameCaseCallback struct{} | ||
|
||
func (*MyNameCaseCallback) Test() {} | ||
|
||
func TestNameCaseCompiles(t *testing.T) { | ||
_ = EnumTestVariantOne | ||
_ = AssociatedEnumTestVariantTest{0} | ||
|
||
var expectedError *ErrorTestVariantOne | ||
errors.As(NewErrorTestVariantOne(), &expectedError) | ||
|
||
var expectedAssociatedError *AssociatedErrorTestVariantTest | ||
errors.As(NewAssociatedErrorTestVariantTest(0), &expectedAssociatedError) | ||
|
||
var _ *ObjectTest = NewObjectTest() | ||
_ = RecordTest{0} | ||
var _ CallbackTest = &MyNameCaseCallback{} | ||
} |
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
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,24 @@ | ||
[package] | ||
name = "uniffi-go-fixture-name-case" | ||
version = "0.22.0" | ||
authors = ["Firefox Sync Team <[email protected]>"] | ||
edition = "2021" | ||
license = "MPL-2.0" | ||
publish = false | ||
|
||
[lib] | ||
name = "uniffi_go_name_case" | ||
crate-type = ["lib", "cdylib"] | ||
|
||
[dependencies] | ||
thiserror = "1.0" | ||
uniffi = { path = "../../3rd-party/uniffi-rs/uniffi" } | ||
|
||
[build-dependencies] | ||
uniffi = {path = "../../3rd-party/uniffi-rs/uniffi", features = ["build"] } | ||
|
||
[dev-dependencies] | ||
glob = "0.3" | ||
uniffi = {path = "../../3rd-party/uniffi-rs/uniffi", features = ["bindgen-tests"] } | ||
uniffi_bindgen = { path = "../../3rd-party/uniffi-rs/uniffi_bindgen" } | ||
uniffi_testing = { path = "../../3rd-party/uniffi-rs/uniffi_testing" } |
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,3 @@ | ||
# A basic test for uniffi components | ||
|
||
This test covers case senstitivity for generate code. |
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,7 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
fn main() { | ||
uniffi::generate_scaffolding("./src/name-case.udl").unwrap(); | ||
} |
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,51 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
include!(concat!(env!("OUT_DIR"), "/name-case.uniffi.rs")); | ||
|
||
pub enum ENUMTest { | ||
VARIANTOne, | ||
} | ||
|
||
pub enum AssociatedENUMTest { | ||
VARIANTTest { code: i16 }, | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum ERRORTest { | ||
#[error("Test")] | ||
VARIANTOne, | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum AssociatedERRORTest { | ||
#[error("Test")] | ||
VARIANTTest { code: i16 }, | ||
} | ||
|
||
pub struct OBJECTTest {} | ||
|
||
impl OBJECTTest { | ||
pub fn new() -> Self { | ||
OBJECTTest {} | ||
} | ||
|
||
pub fn new_alternate() -> Self { | ||
OBJECTTest {} | ||
} | ||
|
||
pub fn test(&self) {} | ||
} | ||
|
||
pub struct RECORDTest { | ||
test: i32, | ||
} | ||
|
||
pub fn test() { | ||
let _ = ERRORTest::VARIANTOne; | ||
} | ||
|
||
pub trait CALLBACKTest { | ||
fn test(&self); | ||
} |
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,35 @@ | ||
namespace name_case { | ||
void test(); | ||
}; | ||
|
||
enum ENUMTest { "VARIANTOne" }; | ||
|
||
[Enum] | ||
interface AssociatedENUMTest { | ||
VARIANTTest(i16 code); | ||
}; | ||
|
||
[Error] | ||
enum ERRORTest { "VARIANTOne" }; | ||
|
||
[Error] | ||
interface AssociatedERRORTest { | ||
VARIANTTest(i16 code); | ||
}; | ||
|
||
interface OBJECTTest { | ||
constructor(); | ||
|
||
[Name="new_alternate"] | ||
constructor(); | ||
|
||
void test(); | ||
}; | ||
|
||
dictionary RECORDTest { | ||
i32 test; | ||
}; | ||
|
||
callback interface CALLBACKTest { | ||
void test(); | ||
}; |
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