-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christophe Larsonneur
committed
Aug 11, 2018
1 parent
75e2196
commit 880157c
Showing
5 changed files
with
109 additions
and
34 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,54 @@ | ||
package forjfile | ||
|
||
import ( | ||
"testing" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValue(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
value := ForjValue{} | ||
|
||
assert.Equal(false, value.SetDefault(""), "It should return false when default value is empty and not changed.") | ||
assert.Equal("", value.default_value, "Default value should be empty") | ||
|
||
assert.Equal(true, value.SetDefault("default"), "It should return true when default value is set") | ||
assert.Equal("default", value.default_value, "Default value should be empty") | ||
|
||
assert.Equal(false, value.Set(""), "It should return false when value to set is empty and not changed.") | ||
assert.Equal("", value.value, "Value should be empty") | ||
|
||
assert.Equal("default", value.Get(), "It should return the default value") | ||
assert.Equal(true, value.Set("value"), "It should consider value to be updated when set it.") | ||
assert.Equal(false, value.Set("value"), "It should consider value not to be updated when set it.") | ||
assert.Equal(false, value.IsDefault(), "It should return false to IsDefault.") | ||
assert.Equal("value", value.Get(), "It should return the value") | ||
assert.Equal(true, value.Set(""), "It should return true when value to set is empty and changed.") | ||
assert.Equal("default", value.Get(), "It should return the default value, when value is empty") | ||
assert.Equal(true, value.IsDefault(), "it should return true if is default value") | ||
|
||
value.Set("blabla") | ||
|
||
value.Clean("") | ||
|
||
assert.Equal("", value.default_value, "It should be cleaned up.") | ||
assert.Equal("", value.value, "It should be cleaned up.") | ||
|
||
yml, err := yaml.Marshal(value) | ||
assert.NoError(err, "No error reported, even empty.") | ||
value2 := ForjValue{} | ||
err = yaml.Unmarshal(yml, &value2) | ||
assert.NoError(err, "No error reported, even empty.") | ||
assert.Empty(value.Get(), "It should return an empty string. no default saved.") | ||
|
||
value.Set("value") | ||
yml, err = yaml.Marshal(value) | ||
assert.NoError(err, "No error reported.") | ||
err = yaml.Unmarshal(yml, &value2) | ||
assert.NoError(err, "No error reported.") | ||
assert.Equal("value", value.Get(), "It should return the value saved/restored.") | ||
} |
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 @@ | ||
package forjfile | ||
|
||
// TODO: Add a function/cap to forjj to generate Forjfile with Default values (ForjValueSelectDefault = true) | ||
var ForjValueSelectDefault bool | ||
|
||
type ForjValues map[string]ForjValue | ||
|
||
// Map returns a map[string]string of all values stored. | ||
// | ||
// It returns values setup with Set and if not found, | ||
// returns Default value. | ||
func (v ForjValues) Map() (values map[string]string) { | ||
values = make(map[string]string) | ||
for key, value := range v { | ||
if v1, f1 := value.get_selected() ; f1 { | ||
values[key] = v1 | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (v ForjValues) MarshalYAML() (interface{}, error) { | ||
values := make(map[string]string) | ||
|
||
for key, value := range v { | ||
if v1, f1 := value.get_selected() ; f1 { | ||
values[key] = v1 | ||
} | ||
} | ||
return values, nil | ||
} |
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