| 1 |
import std.conv; |
| 2 |
import std.stdio; |
| 3 |
import std.array : split; |
| 4 |
import std.string : strip; |
| 5 |
|
| 6 |
import extra; |
| 7 |
|
| 8 |
auto getMenu () |
| 9 |
{ |
| 10 |
auto foods = import ("food.txt").strip.split ("\n"); |
| 11 |
return foods; |
| 12 |
} |
| 13 |
|
| 14 |
auto getPeople () |
| 15 |
{ |
| 16 |
return import ("people.txt").strip.split ("\n"); |
| 17 |
} |
| 18 |
|
| 19 |
// Put these in templates to prevent the compiler from failing to parse them |
| 20 |
// since frontend version 2.111 |
| 21 |
template VersionInt (int v) { |
| 22 |
mixin(`version(` ~ v.to!string ~ `) |
| 23 |
enum VersionInt = true; |
| 24 |
else |
| 25 |
enum VersionInt = false;`); |
| 26 |
} |
| 27 |
template DebugInt (int v) { |
| 28 |
import std.conv; |
| 29 |
mixin(`debug(` ~ v.to!string ~ `) |
| 30 |
enum DebugInt = true; |
| 31 |
else |
| 32 |
enum DebugInt = false;`); |
| 33 |
} |
| 34 |
|
| 35 |
void main (string[] args) |
| 36 |
{ |
| 37 |
import std.array : join; |
| 38 |
import core.stdc.stdlib : exit; |
| 39 |
|
| 40 |
immutable request = args[1]; |
| 41 |
if (request == "menu") { |
| 42 |
version (No_Menu) { |
| 43 |
} else { |
| 44 |
writeln ("On the menu: ", getMenu.join (", ")); |
| 45 |
exit (0); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
version (With_People) { |
| 50 |
if (request == "people") { |
| 51 |
writeln ("People: ", getPeople.join (", ")); |
| 52 |
|
| 53 |
// only exit successfully if the second module also had its module version set. |
| 54 |
// this checks for issue https://github.com/mesonbuild/meson/issues/3337 |
| 55 |
if (secondModulePeopleVersionSet ()) |
| 56 |
exit (0); |
| 57 |
exit (1); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
version (With_VersionInteger) |
| 62 |
static if (VersionInt!3) exit(0); |
| 63 |
|
| 64 |
version (With_Debug) |
| 65 |
debug exit(0); |
| 66 |
|
| 67 |
version (With_DebugInteger) |
| 68 |
static if (DebugInt!(3)) exit(0); |
| 69 |
|
| 70 |
version (With_DebugIdentifier) |
| 71 |
debug(DebugIdentifier) exit(0); |
| 72 |
|
| 73 |
version (With_DebugAll) { |
| 74 |
int dbg = 0; |
| 75 |
debug dbg++; |
| 76 |
static if (DebugInt!2) dbg++; |
| 77 |
static if (DebugInt!3) dbg++; |
| 78 |
static if (DebugInt!4) dbg++; |
| 79 |
debug(DebugIdentifier) dbg++; |
| 80 |
|
| 81 |
if (dbg == 5) |
| 82 |
exit(0); |
| 83 |
} |
| 84 |
|
| 85 |
// we fail here |
| 86 |
exit (1); |
| 87 |
} |
| 88 |
|
| 89 |
unittest |
| 90 |
{ |
| 91 |
writeln ("TEST"); |
| 92 |
import core.stdc.stdlib : exit; |
| 93 |
|
| 94 |
writeln(getMenu); |
| 95 |
assert (getMenu () == ["Spam", "Eggs", "Spam", "Baked Beans", "Spam", "Spam"]); |
| 96 |
|
| 97 |
exit (0); |
| 98 |
} |