Compare commits

..

4 commits

Author SHA1 Message Date
892378f55f Merge branch 'gitlab-ci' into 'master'
added initial .gitlab-ci.yml file

See merge request fsimphy/bayernfahrplan!9
2017-10-28 15:55:08 +02:00
6ad2048907 added initial .gitlab-ci.yml file 2017-10-28 15:46:44 +02:00
e85289fe53 Merge branch 'update_dependencies_and_gitignore' into 'master'
updated dependencies and .gitignore file

See merge request fsimphy/bayernfahrplan!8
2017-10-28 15:41:52 +02:00
18de7f6998 updated dependencies and .gitignore file 2017-10-28 15:39:03 +02:00
5 changed files with 132 additions and 181 deletions

5
.gitignore vendored
View file

@ -1 +1,4 @@
/bayernfahrplan
bayernfahrplan*
.dub/*
replacement.txt
dub.selections.json

19
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,19 @@
image: base/devel
before_script:
- pacman -Sy
- pacman --noconfirm -S ldc dub libevent
stages:
- build
- test
build:
stage: build
script:
- dub build --compiler=ldc2
test:
stage: test
script:
- dub test --compiler=ldc2

View file

@ -5,24 +5,10 @@
"Oliver Rümpelein"
],
"dependencies": {
"requests": "~>0.5.0",
"requests": "0.5.3",
"kxml": "~>1.0.1"
},
"description": "A minimal D application.",
"copyright": "Copyright © 2017, Johannes Loher",
"license": "MIT",
"targetType": "executable",
"configurations": [
{ "name": "executable" },
{
"name": "unittest",
"targetType": "executable",
"preBuildCommands": ["dub run unit-threaded -c gen_ut_main -- -f gen/ut.d"],
"mainSourceFile": "gen/ut.d",
"excludedSourceFiles": ["source/app.d"],
"dependencies": {
"unit-threaded": "~>0.7.28"
}
}
]
"license": "MIT"
}

View file

@ -1,17 +1,12 @@
module fahrplanparser;
import kxml.xml : readDocument, XmlNode;
import std.algorithm : map;
import std.array : empty, front;
import std.conv : to;
import std.datetime : dur, TimeOfDay, DateTimeException;
import std.string : format;
version (unittest)
{
import unit_threaded;
}
import kxml.xml : readDocument, XmlNode;
import substitution;
@ -55,74 +50,22 @@ auto parsedFahrplan(in string data)
{
import std.array : array;
"".parsedFahrplan.array.shouldEqual([]);
auto xml = "";
assert(xml.parsedFahrplan.array == []);
"<efa><dps></dps></efa>".parsedFahrplan.array.shouldEqual([]);
xml = "<efa><dps></dps></efa>";
assert(xml.parsedFahrplan.array == []);
q"[
<efa>
<dps>
<dp>
<realtime>1</realtime>
<st>
<t>1224</t>
<rt>1242</rt>
</st>
<m>
<nu>6</nu>
<des>Wernerwerkstraße</des>
</m>
</dp>
</dps>
</efa>
]".parsedFahrplan.array.shouldEqual([["direction" : "Wernerwerkstraße",
xml = "<efa><dps><dp><realtime>1</realtime><st><t>1224</t><rt>1242</rt></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp></dps></efa>";
assert(xml.parsedFahrplan.array == [["direction" : "Wernerwerkstraße",
"line" : "6", "departure" : "12:24", "delay" : "18"]]);
q"[
<efa>
<dps>
<dp>
<realtime>0</realtime>
<st>
<t>1224</t>
</st>
<m>
<nu>6</nu>
<des>Wernerwerkstraße</des>
</m>
</dp>
</dps>
</efa>
]".parsedFahrplan.array.shouldEqual([["direction" : "Wernerwerkstraße",
xml = "<efa><dps><dp><realtime>0</realtime><st><t>1224</t></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp></dps></efa>";
assert(xml.parsedFahrplan.array == [["direction" : "Wernerwerkstraße",
"line" : "6", "departure" : "12:24", "delay" : "0"]]);
q"[
<efa>
<dps>
<dp>
<realtime>0</realtime>
<st>
<t>1224</t>
</st>
<m>
<nu>6</nu>
<des>Wernerwerkstraße</des>
</m>
</dp>
<dp>
<realtime>1</realtime>
<st>
<t>1353</t>
<rt>1356</rt>
</st>
<m>
<nu>11</nu>
<des>Burgweinting</des>
</m>
</dp>
</dps>
</efa>
]".parsedFahrplan.array.shouldEqual([["direction" : "Wernerwerkstraße", "line" : "6",
xml = "<efa><dps><dp><realtime>0</realtime><st><t>1224</t></st><m><nu>6</nu><des>Wernerwerkstraße</des></m></dp><dp><realtime>1</realtime><st><t>1353</t><rt>1356</rt></st><m><nu>11</nu><des>Burgweinting</des></m></dp></dps></efa>";
assert(xml.parsedFahrplan.array == [["direction" : "Wernerwerkstraße", "line" : "6",
"departure" : "12:24", "delay" : "0"], ["direction" : "Burgweinting",
"line" : "11", "departure" : "13:53", "delay" : "3"]]);
}
@ -161,47 +104,41 @@ body
@system unittest
{
"<dp><st><t>0000</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldEqual(TimeOfDay(0, 0));
import std.exception : assertThrown;
"<dp><st><t>0013</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldEqual(TimeOfDay(0, 13));
auto xml = "<dp><st><t>0000</t></st></dp>".readDocument.parseXPath("/dp").front;
assert(xml.departureTime == TimeOfDay(0, 0));
"<dp><st><t>1100</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldEqual(TimeOfDay(11, 00));
xml = "<dp><st><t>0013</t></st></dp>".readDocument.parseXPath("/dp").front;
assert(xml.departureTime == TimeOfDay(0, 13));
"<dp><st><t>1242</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldEqual(TimeOfDay(12, 42));
xml = "<dp><st><t>1100</t></st></dp>".readDocument.parseXPath("/dp").front;
assert(xml.departureTime == TimeOfDay(11, 00));
"<dp><st><t>2359</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldEqual(TimeOfDay(23, 59));
xml = "<dp><st><t>1242</t></st></dp>".readDocument.parseXPath("/dp").front;
assert(xml.departureTime == TimeOfDay(12, 42));
"<dp><st><t>2400</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
xml = "<dp><st><t>2359</t></st></dp>".readDocument.parseXPath("/dp").front;
assert(xml.departureTime == TimeOfDay(23, 59));
"<dp><st><t>0061</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t>2567</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t></t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t>0</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t>00</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t>000000</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t>00:00</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
"<dp><st><t>abcd</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime.shouldThrow!DateTimeException;
assertThrown!DateTimeException("<dp><st><t>2400</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>0061</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>2567</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t></t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>0</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>00</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>000000</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>00:00</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
assertThrown!DateTimeException("<dp><st><t>abcd</t></st></dp>".readDocument.parseXPath("/dp")
.front.departureTime);
}
auto delay(XmlNode dp)
@ -236,59 +173,70 @@ body
@system unittest
{
import std.exception : assertThrown;
import core.exception : AssertError;
"<dp><realtime>0</realtime></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(0));
auto xml = "<dp><realtime>0</realtime></dp>".readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(0));
"<dp><realtime></realtime></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(UnexpectedValueException!string);
xml = "<dp><realtime></realtime></dp>".readDocument.parseXPath("/dp").front;
assertThrown!(UnexpectedValueException!string)(xml.delay);
"<dp><realtime>2</realtime></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(UnexpectedValueException!string);
xml = "<dp><realtime>2</realtime></dp>".readDocument.parseXPath("/dp").front;
assertThrown!(UnexpectedValueException!string)(xml.delay);
"<dp><realtime>a</realtime></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(UnexpectedValueException!string);
xml = "<dp><realtime>a</realtime></dp>".readDocument.parseXPath("/dp").front;
assertThrown!(UnexpectedValueException!string)(xml.delay);
"<dp><realtime>1</realtime></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"seconds"(0));
xml = "<dp><realtime>1</realtime></dp>".readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"seconds"(0));
"<dp><realtime>1</realtime><st><t></t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(DateTimeException);
xml = "<dp><realtime>1</realtime><st><t></t></st></dp>".readDocument.parseXPath("/dp").front;
assertThrown!DateTimeException(xml.delay);
"<dp><realtime>1</realtime><st><rt></rt></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"seconds"(0));
xml = "<dp><realtime>1</realtime><st><rt></rt></st></dp>".readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"seconds"(0));
"<dp><st><rt></rt><t></t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(AssertError);
xml = "<dp><st><rt></rt><t></t></st></dp>".readDocument.parseXPath("/dp").front;
assertThrown!AssertError(xml.delay);
"<dp><realtime>1</realtime><st><rt></rt><t></t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(DateTimeException);
xml = "<dp><realtime>1</realtime><st><rt></rt><t></t></st></dp>".readDocument.parseXPath("/dp")
.front;
assertThrown!DateTimeException(xml.delay);
"<dp><realtime>1</realtime><st><rt>0000</rt><t></t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(DateTimeException);
xml = "<dp><realtime>1</realtime><st><rt>0000</rt><t></t></st></dp>".readDocument.parseXPath("/dp")
.front;
assertThrown!DateTimeException(xml.delay);
"<dp><realtime>1</realtime><st><rt></rt><t>0000</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldThrow!(DateTimeException);
xml = "<dp><realtime>1</realtime><st><rt></rt><t>0000</t></st></dp>".readDocument.parseXPath("/dp")
.front;
assertThrown!DateTimeException(xml.delay);
"<dp><realtime>1</realtime><st><rt>0000</rt><t>0000</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(0));
xml = "<dp><realtime>1</realtime><st><rt>0000</rt><t>0000</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(0));
"<dp><realtime>1</realtime><st><rt>0001</rt><t>0000</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(1));
xml = "<dp><realtime>1</realtime><st><rt>0001</rt><t>0000</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(1));
"<dp><realtime>1</realtime><st><rt>1753</rt><t>1751</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(2));
xml = "<dp><realtime>1</realtime><st><rt>1753</rt><t>1751</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(2));
"<dp><realtime>1</realtime><st><rt>1010</rt><t>1000</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(10));
xml = "<dp><realtime>1</realtime><st><rt>1010</rt><t>1000</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(10));
"<dp><realtime>1</realtime><st><rt>1301</rt><t>1242</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(19));
xml = "<dp><realtime>1</realtime><st><rt>1301</rt><t>1242</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(19));
"<dp><realtime>1</realtime><st><rt>0000</rt><t>1242</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(678));
xml = "<dp><realtime>1</realtime><st><rt>0000</rt><t>1242</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(678));
"<dp><realtime>1</realtime><st><rt>0000</rt><t>2359</t></st></dp>".readDocument.parseXPath("/dp")
.front.delay.shouldEqual(dur!"minutes"(1));
xml = "<dp><realtime>1</realtime><st><rt>0000</rt><t>2359</t></st></dp>"
.readDocument.parseXPath("/dp").front;
assert(xml.delay == dur!"minutes"(1));
}

View file

@ -4,11 +4,6 @@ import std.file : slurp;
import std.meta : AliasSeq;
import std.traits : Parameters;
version (unittest)
{
import unit_threaded;
}
public:
/***********************************
@ -35,7 +30,7 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
}
loadSubstitutionFile!mockSlurpEmpty("");
map.length.shouldEqual(0);
assert(map.length == 0);
static Tuple!(string, string)[] mockSlurpEmptyEntry(Type1, Type2)(string filename,
in char[] format)
@ -44,9 +39,9 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
}
loadSubstitutionFile!mockSlurpEmptyEntry("");
"".shouldBeIn(map);
map.length.shouldEqual(1);
map[""].shouldEqual("");
assert("" in map);
assert(map.length == 1);
assert(map[""] == "");
static Tuple!(string, string)[] mockSlurpSingleEntry(Type1, Type2)(string filename,
in char[] format)
@ -55,9 +50,9 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
}
loadSubstitutionFile!mockSlurpSingleEntry("");
"foo".shouldBeIn(map);
map.length.shouldEqual(1);
map["foo"].shouldEqual("bar");
assert("foo" in map);
assert(map.length == 1);
assert(map["foo"] == "bar");
static Tuple!(string, string)[] mockSlurpMultipleEntries(Type1, Type2)(
string filename, in char[] format)
@ -66,13 +61,13 @@ void loadSubstitutionFile(alias slurpFun = slurp)(string fileName)
}
loadSubstitutionFile!mockSlurpMultipleEntries("");
"".shouldBeIn(map);
"0".shouldBeIn(map);
"Text in".shouldBeIn(map);
map.length.shouldEqual(3);
map[""].shouldEqual("");
map["0"].shouldEqual("1");
map["Text in"].shouldEqual("wird durch diesen ersetzt");
assert("" in map);
assert("0" in map);
assert("Text in" in map);
assert(map.length == 3);
assert(map[""] == "");
assert(map["0"] == "1");
assert(map["Text in"] == "wird durch diesen ersetzt");
}
/***********************************
@ -89,20 +84,20 @@ auto substitute(string s) @safe nothrow
@safe unittest
{
map[""] = "";
"".substitute.shouldEqual("");
assert(substitute("") == "");
map["a"] = "b";
"a".substitute.shouldEqual("b");
assert(substitute("a") == "b");
map["Regensburg Danziger Freiheit"] = "Danziger Freiheit";
"Regensburg Danziger Freiheit".substitute.shouldEqual("Danziger Freiheit");
assert(substitute("Regensburg Danziger Freiheit") == "Danziger Freiheit");
map["Regensburg Danziger Freiheit"] = "Anderer Test";
"Regensburg Danziger Freiheit".substitute.shouldEqual("Anderer Test");
assert(substitute("Regensburg Danziger Freiheit") == "Anderer Test");
"z".substitute.shouldEqual("z");
assert(substitute("z") == "z");
"Regensburg Hauptbahnhof".substitute.shouldEqual("Regensburg Hauptbahnhof");
assert(substitute("Regensburg Hauptbahnhof") == "Regensburg Hauptbahnhof");
}
private: