From c3b21d081403c086162b2677d4ddf9747202c0fd Mon Sep 17 00:00:00 2001
From: Alexis Bridoux
Date: Mon, 30 Mar 2020 18:31:15 +0200
Subject: [PATCH] Xml stringValue not empty because of newline
Also added a small test bash script for basic testing. To be improved.
---
CHANGELOG.md | 5 +
README.md | 7 -
Sources/Scout/Constants/Version.swift | 2 +-
.../PathExplorerXML+PathExplorer.swift | 2 +-
clt-test.sh | 127 ++++++++++++++++++
5 files changed, 134 insertions(+), 9 deletions(-)
create mode 100755 clt-test.sh
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 781436f..1f80c10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file. `Scout` adheres to [Semantic Versioning](http://semver.org).
---
+## [1.0.2](https://github.com/ABridoux/scout/tree/1.0.2) (30/03/2020)
+
+### Fixed
+- `PathExplorerXml` string value not empty because of new line.
+
## [1.0.1](https://github.com/ABridoux/scout/tree/1.0.1) (30/03/2020)
### Fixed
diff --git a/README.md b/README.md
index 158941a..6fca62d 100644
--- a/README.md
+++ b/README.md
@@ -18,13 +18,6 @@ Install:
-Donwloads:
-
-
-
-
-
-
# Scout
diff --git a/Sources/Scout/Constants/Version.swift b/Sources/Scout/Constants/Version.swift
index e2c8f75..ce98b7d 100644
--- a/Sources/Scout/Constants/Version.swift
+++ b/Sources/Scout/Constants/Version.swift
@@ -1,3 +1,3 @@
public struct Version {
- public static let current = "1.0.1"
+ public static let current = "1.0.2"
}
diff --git a/Sources/Scout/Implementations/PathExplorerXML+PathExplorer.swift b/Sources/Scout/Implementations/PathExplorerXML+PathExplorer.swift
index 3c1d237..9cfdd92 100644
--- a/Sources/Scout/Implementations/PathExplorerXML+PathExplorer.swift
+++ b/Sources/Scout/Implementations/PathExplorerXML+PathExplorer.swift
@@ -4,7 +4,7 @@ extension PathExplorerXML: PathExplorer {
public var int: Int? { element.int }
public var real: Double? { element.double }
- public var stringValue: String { element.string }
+ public var stringValue: String { element.string.trimmingCharacters(in: .whitespacesAndNewlines) }
public var description: String { element.xml }
diff --git a/clt-test.sh b/clt-test.sh
new file mode 100755
index 0000000..12f190f
--- /dev/null
+++ b/clt-test.sh
@@ -0,0 +1,127 @@
+# ---- Colors ----
+
+COLOR_FAILURE='\033[0;31m'
+COLOR_SUCCESS='\033[0;32m'
+COLOR_NC='\033[0m' # No Color
+
+function error {
+ echo "${COLOR_FAILURE}$1${COLOR_NC}"
+ exit 1
+}
+
+function success {
+ echo "${COLOR_SUCCESS}$1${COLOR_NC}"
+}
+
+# ---- Files ----
+
+json=Playground/People.json
+plist=Playground/People.plist
+xml=Playground/People.xml
+
+function format {
+ echo "${1##*.}"
+}
+# ---- Test functions ----
+
+function testGet {
+ fileFormat=`format $3`
+ expected=$2
+ result=`scout $1 -i $3`
+
+ if [ "$result" != "$expected" ]; then
+ error "Error $fileFormat get. '$1' = $result != $expected"
+ fi
+}
+
+function testGetAll {
+ expected=$2
+
+ echo "Testing get at '$1'..."
+
+ testGet "$1" "$2" $json
+ testGet "$1" "$2" $plist
+ testGet "$1" "$2" $xml
+ success "All test formats passed"
+ echo ""
+}
+
+function testSet {
+ fileFormat=`format $3`
+ modified=`scout set "$1=$2" -i $3 -v`
+ valueAtPath=`echo "$modified" | scout $1`
+
+ if [ "$valueAtPath" != "$2" ]; then
+ error "Error $fileFormat set. '$1': expected $2 and got $valueAtPath"
+ fi
+}
+
+function testSetAll {
+ expected=$2
+
+ echo "Testing set at '$1'..."
+
+ testSet "$1" "$2" $json
+ testSet "$1" "$2" $plist
+ testSet "$1" "$2" $xml
+ success "All test formats passed"
+ echo ""
+}
+
+# ---- Tests ----
+
+# Get
+echo "-- Testing Get --"
+testGetAll people.Tom.height 175
+testGetAll people.Tom.hobbies[-1] guitar
+testGetAll people.Tom.hobbies[0] cooking
+testGetAll people.Suzanne.movies[0].title "Tomorrow is so far"
+testGetAll people.Robert.running_records[1][0] 9
+
+# -- Test dictionary --
+
+TomJson='{
+ "age" : 68,
+ "hobbies" : [
+ "cooking",
+ "guitar"
+ ],
+ "height" : 175
+}'
+testGet people.Tom "$TomJson" $json
+
+TomPlist='
+
+
+
+ age
+ 68
+ height
+ 175
+ hobbies
+
+ cooking
+ guitar
+
+
+'
+
+testGet people.Tom "$TomPlist" $plist
+
+TomXml='
+ 175
+ 68
+
+ cooking
+ guitar
+
+'
+
+testGet people.Tom "$TomXml" $xml
+
+# Set
+echo "-- Testing Set --"
+
+testSetAll people.Robert.age 60
+testSetAll people.Suzanne.movies[1].title "Never gonna die"
+testSetAll people.Robert.running_records[0][2] 15
\ No newline at end of file