Skip to content

Commit

Permalink
handling multiple separators (#650)
Browse files Browse the repository at this point in the history
# Description
Generator would break with the [new DBaaS enums for
Datadog](https://github.com/exoscale/dbaas-api/blob/40b1ba53298095740a736f55905f3e4aff62a542/modules/dbaas-schemas/resources/schemas/dbaas-api.edn#L2562)

```clojure
  :enum-datadog-site
  #{"us3.datadoghq.com"
    "ddog-gov.com"
    "datadoghq.eu"
    "us5.datadoghq.com"
    "ap1.datadoghq.com"
    "datadoghq.com"}
```
For the entry "ddog-gov.com" the existing code considers only one
separator and it generates
```go
EnumDatadogSiteDdogGov.com      EnumDatadogSite = "ddog-gov.com"
```

With these changes it would generate 
```go
EnumDatadogSiteDdogGovCom      EnumDatadogSite = "ddog-gov.com"
```

## Checklist
(For exoscale contributors)

* [x] Changelog updated (under *Unreleased* block)
* [x] For a new resource or new attributes: test added/updated

---------

Co-authored-by: Philipp Sauter <philipp.sauter@exoscale.ch>
  • Loading branch information
simisoft-exo and sauterp authored Aug 16, 2024
1 parent fb4bcaf commit d380d78
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased
----------

- generate_v3: replace deprecated ::set-output #647
- generate_v3: handle multiple separators #650

3.1.1
----------
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GO_MK_REF := v2.0.0
GO_MK_REF := v2.0.2

# make go.mk a dependency for all targets
.EXTRA_PREREQS = go.mk
Expand Down
2 changes: 1 addition & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestRequest(t *testing.T) {
}
resp, err := cs.Request(req)
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
apis := resp.(*ListAPIsResponse)
if apis.Count != 1 {
Expand Down
42 changes: 19 additions & 23 deletions v3/generator/helpers/helpers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions v3/generator/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ func TestToCamel(t *testing.T) {
require.Equal(t, "Test", ToCamel("test"))
require.Equal(t, "", ToCamel("."))
require.Equal(t, "TestFoo", ToCamel("test...foo"))

// trimming
require.Equal(t, "Test", ToCamel("---test"))
require.Equal(t, "Test", ToCamel("test___"))
require.Equal(t, "Test", ToCamel(".-_test_-."))
require.Equal(t, "Test", ToCamel(" test "))
require.Equal(t, "Test", ToCamel(" .-_test_-. "))

// splitting
require.Equal(t, "TestFooBarBaz", ToCamel("test-foo_bar.baz"))
require.Equal(t, "TestFooBar", ToCamel("test--_foo..bar"))
require.Equal(t, "TESTFooBAR", ToCamel("TEST-Foo-BAR"))
require.Equal(t, "Test123Foo", ToCamel("test-123-foo"))
require.Equal(t, "123", ToCamel("1-2-3"))

// trimming and splitting
require.Equal(t, "TrimMixedSeparators", ToCamel("-_. trim-mixed/separators ._-"))

// Acronym handling
require.Equal(t, "HandleXMLHTTPRequest", ToCamel("handle-xml-http-request"))
require.Equal(t, "ParseJSONAPI", ToCamel("parse_json_api"))
require.Equal(t, "NewURLForID", ToCamel("new-url-for-id"))
require.Equal(t, "SupportSQLQueries", ToCamel("support-sql-queries"))

}

func TestToLowerCamel(t *testing.T) {
Expand Down

0 comments on commit d380d78

Please sign in to comment.