-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse common computed types (#131)
* parse basic types from computed properties * add note about computed property types * only build once * new snapshot w/ type info * more specific documentation on parsing * simplify BuildVars arguments * use build int bool parser * build vars tests
- Loading branch information
Showing
13 changed files
with
175 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
questions: | ||
- name: langs | ||
prompt: | ||
multi: true | ||
message: "Languages to be used in the project" | ||
options: | ||
- JavaScript & TypeScript | ||
- Python | ||
|
||
computed: | ||
javascript: '{{ has "JavaScript & TypeScript" .Scaffold.langs }}' | ||
python: '{{ has "Python" .Scaffold.langs }}' | ||
int: "1" | ||
basicint: "{{ add 1 2 }}" | ||
|
||
presets: | ||
default: | ||
Project: "scaffold-test-defaults" | ||
langs: ["Python"] |
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,8 @@ | ||
Has Javascript | ||
{{ .Computed.javascript }} (type={{ typeOf .Computed.javascript }}) | ||
Has Python | ||
{{ .Computed.python }} (type={{ typeOf .Computed.python }}) | ||
Should Be Int | ||
{{ .Computed.int }} (type={{ typeOf .Computed.int }}) | ||
Basic Int | ||
{{ .Computed.basicint }} (type={{ typeOf .Computed.basicint }}) |
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,78 @@ | ||
package scaffold | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hay-kot/scaffold/app/core/engine" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_BuildVars(t *testing.T) { | ||
project := &Project{ | ||
Name: "test", | ||
Conf: &ProjectScaffoldFile{ | ||
Computed: map[string]string{ | ||
"Bool": "true", | ||
"Int": "{{ add 1 2 }}", | ||
"ZeroInt": "0", | ||
"UsesVars": "Computed: {{ .Scaffold.key }}", | ||
}, | ||
}, | ||
} | ||
|
||
vars := engine.Vars{ | ||
"key": "value", | ||
} | ||
|
||
eng := engine.New() | ||
|
||
got, err := BuildVars(eng, project, vars) | ||
require.NoError(t, err) | ||
|
||
// | ||
// Assert Top Level Keys | ||
// | ||
|
||
requiredStringKeys := []string{ | ||
"Project", | ||
"ProjectSnake", | ||
"ProjectKebab", | ||
"ProjectCamel", | ||
} | ||
|
||
for _, key := range requiredStringKeys { | ||
assert.NotNil(t, got[key]) | ||
assert.IsType(t, "", got[key]) | ||
} | ||
|
||
assert.NotNil(t, got["Scaffold"]) | ||
assert.IsType(t, engine.Vars{}, got["Scaffold"]) | ||
|
||
// | ||
// Assert Passed in Vars live under Scaffold | ||
// | ||
|
||
scaffold := got["Scaffold"].(engine.Vars) | ||
assert.NotNil(t, scaffold["key"]) | ||
|
||
// | ||
// Assert Computed Properties are Typed and Computed | ||
// | ||
|
||
require.NotNil(t, got["Computed"]) | ||
computed := got["Computed"].(map[string]any) | ||
|
||
assert.NotNil(t, computed["Bool"]) | ||
assert.IsType(t, true, computed["Bool"]) | ||
|
||
assert.NotNil(t, computed["Int"]) | ||
assert.IsType(t, 3, computed["Int"]) | ||
|
||
assert.NotNil(t, computed["ZeroInt"]) | ||
assert.IsType(t, 0, computed["ZeroInt"]) | ||
|
||
assert.NotNil(t, computed["UsesVars"]) | ||
assert.IsType(t, "", computed["UsesVars"]) | ||
assert.Equal(t, "Computed: value", computed["UsesVars"]) | ||
} |
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
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,11 @@ | ||
scaffold-test-defaults: (type=dir) | ||
types.txt: (type=file) | ||
Has Javascript | ||
false (type=bool) | ||
Has Python | ||
true (type=bool) | ||
Should Be Int | ||
1 (type=int) | ||
Basic Int | ||
3 (type=int) | ||
|
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,15 @@ | ||
#!/bin/bash | ||
|
||
# Source the assert_snapshot function | ||
source tests/assert.sh | ||
|
||
# Your script continues as before... | ||
output=$($1 --log-level="error" \ | ||
new \ | ||
--preset="default" \ | ||
--no-prompt \ | ||
--snapshot="stdout" \ | ||
types) | ||
|
||
# Call the function to assert the snapshot | ||
assert_snapshot "types.snapshot.txt" "$output" |