aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/eu/equalparts/cardbase/cli/CardbaseCLI.java16
-rw-r--r--test/Testest.java1
-rw-r--r--test/eu/equalparts/test/cardbase/testcards.json2
-rw-r--r--test/eu/equalparts/test/ui/CardbaseCLITest.java5
-rw-r--r--todo6
5 files changed, 22 insertions, 8 deletions
diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
index e1b912d..d6e1cdd 100644
--- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
+++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
@@ -134,6 +134,16 @@ public class CardbaseCLI {
}
}
+
+ /**
+ * Properly sanitise user input.
+ *
+ * @param input the raw input from the user.
+ * @return an array of strings, where the first element is the command and subsequent elements are the arguments.
+ */
+ public String[] sanitiseInput(String input) {
+ return input.trim().split("[ \t]+");
+ }
/**
* Read stdin for user input, sanitise and interpret any commands entered.
@@ -146,9 +156,9 @@ public class CardbaseCLI {
// print prompt
System.out.print(selectedSet == null ? "> " : selectedSet.code + " > ");
// condition input and interpret
- String[] raw = consoleReader.readLine().trim().split("[ \t]+");
- String command = raw[0];
- String[] args = Arrays.copyOfRange(raw, 1, raw.length);
+ String[] input = sanitiseInput(consoleReader.readLine());
+ String command = input[0];
+ String[] args = Arrays.copyOfRange(input, 1, input.length);
if (command.equalsIgnoreCase("help")) {
help();
diff --git a/test/Testest.java b/test/Testest.java
index 25843d7..6fe041d 100644
--- a/test/Testest.java
+++ b/test/Testest.java
@@ -4,6 +4,5 @@ public class Testest {
public static void main(String... args) throws Exception {
-
}
}
diff --git a/test/eu/equalparts/test/cardbase/testcards.json b/test/eu/equalparts/test/cardbase/testcards.json
index cccd8a4..18b3783 100644
--- a/test/eu/equalparts/test/cardbase/testcards.json
+++ b/test/eu/equalparts/test/cardbase/testcards.json
@@ -1 +1 @@
-[{"name":"Callow Jushi","layout":"flip","manaCost":"{1}{U}{U}","cmc":3,"type":"Creature — Human Wizard","rarity":"Uncommon","text":"Whenever you cast a Spirit or Arcane spell, you may put a ki counter on Callow Jushi.\nAt the beginning of the end step, if there are two or more ki counters on Callow Jushi, you may flip it.","flavor":null,"artist":"Tsutomu Kawade","number":"31a","power":"2","toughness":"2","loyalty":null,"multiverseid":74489,"imageName":"callow jushi","border":null,"watermark":null,"setCode":"BOK","imageCode":"bok","count":1},{"name":"Coerced Confession","layout":"normal","manaCost":"{4}{U/B}","cmc":5,"type":"Sorcery","rarity":"Uncommon","text":"Target player puts the top four cards of his or her library into his or her graveyard. You draw a card for each creature card put into that graveyard this way.","flavor":"\"Ask the right questions in the right way and truth is inevitable.\"\n—Lazav","artist":"Mathias Kollros","number":"217","power":null,"toughness":null,"loyalty":null,"multiverseid":366408,"imageName":"coerced confession","border":null,"watermark":"Dimir","setCode":"GTC","imageCode":"gtc","count":2},{"name":"Khalni Hydra","layout":"normal","manaCost":"{G}{G}{G}{G}{G}{G}{G}{G}","cmc":8,"type":"Creature — Hydra","rarity":"Mythic Rare","text":"Khalni Hydra costs {G} less to cast for each green creature you control.\nTrample","flavor":"\"In ages past, bargains were struck and promises were made. Now we must collect on our debt. Begin the hymns.\"\n—Moruul, Khalni druid","artist":"Todd Lockwood","number":"192","power":"8","toughness":"8","loyalty":null,"multiverseid":193551,"imageName":"khalni hydra","border":null,"watermark":null,"setCode":"ROE","imageCode":"roe","count":3},{"name":"Nightmare","layout":"normal","manaCost":"{5}{B}","cmc":6,"type":"Creature — Nightmare Horse","rarity":"Rare","text":"Flying (This creature can't be blocked except by creatures with flying or reach.)\nNightmare's power and toughness are each equal to the number of Swamps you control.","flavor":"The thunder of its hooves beats dreams into despair.","artist":"Vance Kovacs","number":"276","power":"*","toughness":"*","loyalty":null,"multiverseid":383168,"imageName":"nightmare","border":null,"watermark":null,"setCode":"M15","imageCode":"m15","count":8},{"name":"Shivan Dragon","layout":"normal","manaCost":"{4}{R}{R}","cmc":6,"type":"Creature — Dragon","rarity":"Rare","text":"Flying (This creature can't be blocked except by creatures with flying or reach.)\n{R}: Shivan Dragon gets +1/+0 until end of turn.","flavor":"The undisputed master of the mountains of Shiv.","artist":"Donato Giancola","number":"281","power":"5","toughness":"5","loyalty":null,"multiverseid":383172,"imageName":"shivan dragon","border":null,"watermark":null,"setCode":"M15","imageCode":"m15","count":1},{"name":"Disrupting Shoal","layout":"normal","manaCost":"{X}{U}{U}","cmc":2,"type":"Instant — Arcane","rarity":"Rare","text":"You may exile a blue card with converted mana cost X from your hand rather than pay Disrupting Shoal's mana cost.\nCounter target spell if its converted mana cost is X.","flavor":null,"artist":"Scott M. Fischer","number":"33","power":null,"toughness":null,"loyalty":null,"multiverseid":74128,"imageName":"disrupting shoal","border":null,"watermark":null,"setCode":"BOK","imageCode":"bok","count":15},{"name":"Sorin Markov","layout":"normal","manaCost":"{3}{B}{B}{B}","cmc":6,"type":"Planeswalker — Sorin","rarity":"Mythic Rare","text":"+2: Sorin Markov deals 2 damage to target creature or player and you gain 2 life.\n−3: Target opponent's life total becomes 10.\n−7: You control target player during that player's next turn.","flavor":null,"artist":"Michael Komarck","number":"109","power":null,"toughness":null,"loyalty":4,"multiverseid":238330,"imageName":"sorin markov","border":null,"watermark":null,"setCode":"M12","imageCode":"m12","count":1},{"name":"Ugin's Construct","layout":"normal","manaCost":"{4}","cmc":4,"type":"Artifact Creature — Construct","rarity":"Uncommon","text":"When Ugin's Construct enters the battlefield, sacrifice a permanent that's one or more colors.","flavor":"While trapping the Eldrazi on Zendikar, Ugin learned little from Sorin, but he gleaned the rudiments of lithomancy from Nahiri.","artist":"Peter Mohrbacher","number":"164","power":"4","toughness":"5","loyalty":null,"multiverseid":391949,"imageName":"ugin's construct","border":null,"watermark":null,"setCode":"FRF","imageCode":"frf","count":1}]
+[{"name":"Callow Jushi","layout":"flip","manaCost":"{1}{U}{U}","cmc":3,"type":"Creature — Human Wizard","rarity":"Uncommon","text":"Whenever you cast a Spirit or Arcane spell, you may put a ki counter on Callow Jushi.\nAt the beginning of the end step, if there are two or more ki counters on Callow Jushi, you may flip it.","flavor":null,"artist":"Tsutomu Kawade","number":"31a","power":"2","toughness":"2","loyalty":null,"multiverseid":74489,"imageName":"callow jushi","watermark":null,"setCode":"BOK","imageCode":"bok","count":1},{"name":"Coerced Confession","layout":"normal","manaCost":"{4}{U/B}","cmc":5,"type":"Sorcery","rarity":"Uncommon","text":"Target player puts the top four cards of his or her library into his or her graveyard. You draw a card for each creature card put into that graveyard this way.","flavor":"\"Ask the right questions in the right way and truth is inevitable.\"\n—Lazav","artist":"Mathias Kollros","number":"217","power":null,"toughness":null,"loyalty":null,"multiverseid":366408,"imageName":"coerced confession","watermark":"Dimir","setCode":"GTC","imageCode":"gtc","count":2},{"name":"Khalni Hydra","layout":"normal","manaCost":"{G}{G}{G}{G}{G}{G}{G}{G}","cmc":8,"type":"Creature — Hydra","rarity":"Mythic Rare","text":"Khalni Hydra costs {G} less to cast for each green creature you control.\nTrample","flavor":"\"In ages past, bargains were struck and promises were made. Now we must collect on our debt. Begin the hymns.\"\n—Moruul, Khalni druid","artist":"Todd Lockwood","number":"192","power":"8","toughness":"8","loyalty":null,"multiverseid":193551,"imageName":"khalni hydra","watermark":null,"setCode":"ROE","imageCode":"roe","count":3},{"name":"Nightmare","layout":"normal","manaCost":"{5}{B}","cmc":6,"type":"Creature — Nightmare Horse","rarity":"Rare","text":"Flying (This creature can't be blocked except by creatures with flying or reach.)\nNightmare's power and toughness are each equal to the number of Swamps you control.","flavor":"The thunder of its hooves beats dreams into despair.","artist":"Vance Kovacs","number":"276","power":"*","toughness":"*","loyalty":null,"multiverseid":383168,"imageName":"nightmare","watermark":null,"setCode":"M15","imageCode":"m15","count":8},{"name":"Shivan Dragon","layout":"normal","manaCost":"{4}{R}{R}","cmc":6,"type":"Creature — Dragon","rarity":"Rare","text":"Flying (This creature can't be blocked except by creatures with flying or reach.)\n{R}: Shivan Dragon gets +1/+0 until end of turn.","flavor":"The undisputed master of the mountains of Shiv.","artist":"Donato Giancola","number":"281","power":"5","toughness":"5","loyalty":null,"multiverseid":383172,"imageName":"shivan dragon","watermark":null,"setCode":"M15","imageCode":"m15","count":1},{"name":"Disrupting Shoal","layout":"normal","manaCost":"{X}{U}{U}","cmc":2,"type":"Instant — Arcane","rarity":"Rare","text":"You may exile a blue card with converted mana cost X from your hand rather than pay Disrupting Shoal's mana cost.\nCounter target spell if its converted mana cost is X.","flavor":null,"artist":"Scott M. Fischer","number":"33","power":null,"toughness":null,"loyalty":null,"multiverseid":74128,"imageName":"disrupting shoal","watermark":null,"setCode":"BOK","imageCode":"bok","count":15},{"name":"Sorin Markov","layout":"normal","manaCost":"{3}{B}{B}{B}","cmc":6,"type":"Planeswalker — Sorin","rarity":"Mythic Rare","text":"+2: Sorin Markov deals 2 damage to target creature or player and you gain 2 life.\n−3: Target opponent's life total becomes 10.\n−7: You control target player during that player's next turn.","flavor":null,"artist":"Michael Komarck","number":"109","power":null,"toughness":null,"loyalty":4,"multiverseid":238330,"imageName":"sorin markov","watermark":null,"setCode":"M12","imageCode":"m12","count":1},{"name":"Ugin's Construct","layout":"normal","manaCost":"{4}","cmc":4,"type":"Artifact Creature — Construct","rarity":"Uncommon","text":"When Ugin's Construct enters the battlefield, sacrifice a permanent that's one or more colors.","flavor":"While trapping the Eldrazi on Zendikar, Ugin learned little from Sorin, but he gleaned the rudiments of lithomancy from Nahiri.","artist":"Peter Mohrbacher","number":"164","power":"4","toughness":"5","loyalty":null,"multiverseid":391949,"imageName":"ugin's construct","watermark":null,"setCode":"FRF","imageCode":"frf","count":1}] \ No newline at end of file
diff --git a/test/eu/equalparts/test/ui/CardbaseCLITest.java b/test/eu/equalparts/test/ui/CardbaseCLITest.java
index ad81fb9..19662e1 100644
--- a/test/eu/equalparts/test/ui/CardbaseCLITest.java
+++ b/test/eu/equalparts/test/ui/CardbaseCLITest.java
@@ -25,7 +25,10 @@ public class CardbaseCLITest {
@After
public void tearDown() throws Exception {
}
-
+
+ /***********************************************************************************
+ * Constructor tests, happy path
+ ***********************************************************************************/
@Test
public void test() {
fail("Not yet implemented");
diff --git a/todo b/todo
index bca27f5..02933ad 100644
--- a/todo
+++ b/todo
@@ -1,6 +1,8 @@
Cardbase:
- * get card(s)
* decks
CardbaseCLI:
- * everything \ No newline at end of file
+ * construction
+ * user input sanity
+ * command methods
+ * \ No newline at end of file