-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Replace log.Faltal with error wrapping in schemagen func - Simplify tests, use temp dir and ioutil functions, remove boilerplate code - In test use schemagen keyspace to avoid name conflict with examples - Change template
- Loading branch information
Showing
7 changed files
with
233 additions
and
282 deletions.
There are no files selected for viewing
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,43 @@ | ||
// Copyright (C) 2017 ScyllaDB | ||
// Use of this source code is governed by a ALv2-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"unicode" | ||
) | ||
|
||
func camelize(s string) string { | ||
buf := []byte(s) | ||
out := make([]byte, 0, len(buf)) | ||
underscoreSeen := false | ||
|
||
l := len(buf) | ||
for i := 0; i < l; i++ { | ||
if !(allowedBindRune(buf[i]) || buf[i] == '_') { | ||
panic(fmt.Sprint("not allowed name ", s)) | ||
} | ||
|
||
b := rune(buf[i]) | ||
|
||
if b == '_' { | ||
underscoreSeen = true | ||
continue | ||
} | ||
|
||
if (i == 0 || underscoreSeen) && unicode.IsLower(b) { | ||
b = unicode.ToUpper(b) | ||
underscoreSeen = false | ||
} | ||
|
||
out = append(out, byte(b)) | ||
} | ||
|
||
return string(out) | ||
} | ||
|
||
func allowedBindRune(b byte) bool { | ||
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') | ||
} |
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,31 @@ | ||
// Copyright (C) 2017 ScyllaDB | ||
// Use of this source code is governed by a ALv2-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import "testing" | ||
|
||
func TestCamelize(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
want string | ||
}{ | ||
{"hello", "Hello"}, | ||
{"_hello", "Hello"}, | ||
{"__hello", "Hello"}, | ||
{"hello_", "Hello"}, | ||
{"hello_world", "HelloWorld"}, | ||
{"hello__world", "HelloWorld"}, | ||
{"_hello_world", "HelloWorld"}, | ||
{"helloWorld", "HelloWorld"}, | ||
{"HelloWorld", "HelloWorld"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.input, func(t *testing.T) { | ||
if got := camelize(tt.input); got != tt.want { | ||
t.Errorf("camelize() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.