Commit e5b3693b authored by François Chabot's avatar François Chabot

Merge branch '28-windows-init-crlf' into 'master'

init command CRLF handling

Closes #28

See merge request !132
parents 966c27f6 f95e0465
Pipeline #98785147 passed with stages
in 11 minutes and 43 seconds
......@@ -259,9 +259,8 @@ func getActorClassFromReader(reader *bufio.Reader, name string) (totalAi, totalH
}
func getIntegerFromReader(reader *bufio.Reader) (int, error) {
input, _ := reader.ReadString('\n')
input = strings.TrimSuffix(input, "\n")
input = strings.TrimSpace(input)
result, err := strconv.Atoi(input)
if err != nil {
......@@ -288,7 +287,7 @@ func getTotalActorsFromReader(reader *bufio.Reader) (int, error) {
func getActorClassNameFromReader(reader *bufio.Reader) (string, error) {
fmt.Printf("Actor name: ")
input, _ := reader.ReadString('\n')
input = strings.TrimSuffix(input, "\n")
input = strings.TrimSpace(input)
if input == "" {
return input, fmt.Errorf("name can't be empty")
......
......@@ -47,6 +47,48 @@ func TestCreateProjectConfig(t *testing.T) {
assert.Equal(t, expectedConfig, *config)
}
func TestCreateProjectConfigWindows(t *testing.T) {
input := []string{
"2", // nb of actor types
"player red", // name 1st
"1", // nb ai
"1", // nb human
"player white", // name 2nd
"1", // nb ai
"0", // nb human
}
var stdin bytes.Buffer
stdin.Write([]byte(strings.Join(input, "\r\n") + "\r\n"))
config, err := createProjectConfigFromReader(&stdin)
assert.Nil(t, err)
assert.Equal(t, expectedConfig, *config)
}
func TestCreateProjectConfigWhitespace(t *testing.T) {
input := []string{
"2", // nb of actor types
" player red", // name 1st
"1", // nb ai
"1", // nb human
"player white ", // name 2nd
"1", // nb ai
"0", // nb human
}
var stdin bytes.Buffer
stdin.Write([]byte(strings.Join(input, "\n") + "\n"))
config, err := createProjectConfigFromReader(&stdin)
assert.Nil(t, err)
assert.Equal(t, expectedConfig, *config)
}
func TestCreateProjectFiles(t *testing.T) {
dir, err := ioutil.TempDir("", "TestCreateProjectFiles")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment