瀏覽代碼

Some cleanup

Sam Jaffe 4 年之前
父節點
當前提交
e402323c6e
共有 3 個文件被更改,包括 21 次插入17 次删除
  1. 1 0
      include/dice-roll/die.h
  2. 0 3
      src/die.cxx
  3. 20 14
      test/parser_test.cxx

+ 1 - 0
include/dice-roll/die.h

@@ -9,6 +9,7 @@
 #pragma once
 
 #include <iosfwd>
+#include <string>
 #include <vector>
 
 namespace dice {

+ 0 - 3
src/die.cxx

@@ -8,9 +8,6 @@
 
 #include "dice-roll/die.h"
 
-#include <iostream>
-#include <sstream>
-
 #include "dice-roll/exception.h"
 
 namespace dice {

+ 20 - 14
test/parser_test.cxx

@@ -26,18 +26,18 @@ namespace dice {
 
 using namespace ::testing;
 
-TEST(DiceTest, ThrowsOnEmptyString) {
+TEST(Parser, ThrowsOnEmptyString) {
   EXPECT_THROW(dice::from_string(""), dice::unexpected_token);
 }
 
-TEST(DiceTest, ThrowsOnOpeningArithmetic) {
+TEST(Parser, ThrowsOnOpeningArithmetic) {
   EXPECT_THROW(dice::from_string("+5"), dice::unexpected_token);
   EXPECT_THROW(dice::from_string("-5"), dice::unexpected_token);
   EXPECT_THROW(dice::from_string("+1d4"), dice::unexpected_token);
   EXPECT_THROW(dice::from_string("-1d4"), dice::unexpected_token);
 }
 
-TEST(DiceTest, Implicit1dN) {
+TEST(Parser, Implicit1dN) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("d4"));
   EXPECT_THAT(capture.num, Eq(1));
@@ -45,7 +45,7 @@ TEST(DiceTest, Implicit1dN) {
   EXPECT_THAT(capture.of[0], Eq(unsigned_die(1, 4)));
 }
 
-TEST(DiceTest, Explicit1dN) {
+TEST(Parser, Explicit1dN) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("1d4"));
   EXPECT_THAT(capture.num, Eq(1));
@@ -53,11 +53,11 @@ TEST(DiceTest, Explicit1dN) {
   EXPECT_THAT(capture.of[0], Eq(unsigned_die(1, 4)));
 }
 
-TEST(DiceTest, CannotImplicitNumberOfSides) {
+TEST(Parser, CannotImplicitNumberOfSides) {
   EXPECT_THROW(dice::from_string("1d"), dice::unexpected_token);
 }
 
-TEST(DiceTest, AllowsMultipleDice) {
+TEST(Parser, AllowsMultipleDice) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("1d4+1d6"));
   EXPECT_THAT(capture.of, SizeIs(2));
@@ -65,7 +65,7 @@ TEST(DiceTest, AllowsMultipleDice) {
                                       Eq(unsigned_die(1, 6))));
 }
 
-TEST(DiceTest, CanIncludeConstant) {
+TEST(Parser, CanIncludeConstant) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("1d4+1"));
   EXPECT_THAT(capture.of, SizeIs(1));
@@ -73,7 +73,7 @@ TEST(DiceTest, CanIncludeConstant) {
   EXPECT_THAT(capture.modifier[0].value, 1);
 }
 
-TEST(DiceTest, ConstantSignIsInSgnMember) {
+TEST(Parser, ConstantSignIsInSgnMember) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("1d4-1"));
   EXPECT_THAT(capture.of, SizeIs(1));
@@ -81,22 +81,22 @@ TEST(DiceTest, ConstantSignIsInSgnMember) {
   EXPECT_THAT(capture.modifier[0].value, 1);
 }
 
-TEST(DiceTest, ThrowsIfUnterminatedArithmatic) {
+TEST(Parser, ThrowsIfUnterminatedArithmatic) {
   EXPECT_THROW(dice::from_string("1d4+"), dice::unexpected_token);
 }
 
-TEST(DiceTest, CanProduceMultiRollExpression) {
+TEST(Parser, CanProduceMultiRollExpression) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("2{d4}"));
   EXPECT_THAT(capture.num, Eq(2));
   EXPECT_THAT(capture.of, SizeIs(1));
 }
 
-TEST(DiceTest, MultiRollWillThrowIfNoEndBrace) {
+TEST(Parser, MultiRollWillThrowIfNoEndBrace) {
   EXPECT_THROW(dice::from_string("2{d4"), dice::unexpected_token);
 }
 
-TEST(DiceTest, IgnoresWhitespace) {
+TEST(Parser, IgnoresWhitespace) {
   dice::dice capture;
   EXPECT_NO_THROW(capture = dice::from_string("2 { d 4 + 5 }"));
   EXPECT_THAT(capture.num, Eq(2));
@@ -104,13 +104,19 @@ TEST(DiceTest, IgnoresWhitespace) {
   EXPECT_THAT(capture.modifier, SizeIs(1));
 }
 
-TEST(DiceSerialTest, StringFormIsExplicit) {
+TEST(DiceIO, StringFormIsExplicit) {
   std::stringstream ss;
   ss << dice::from_string("2{2d6-d4+5}");
   EXPECT_THAT(ss.str(), Eq("2{2d6-1d4+5}"));
 }
 
-TEST(DiceSerialTest, StringFormDoesNotPreserveWhitespace) {
+TEST(DiceIO, AllModifiersComeAtTheEnd) {
+  std::stringstream ss;
+  ss << dice::from_string("2d6-4-1d6+5");
+  EXPECT_THAT(ss.str(), Eq("2d6-1d6-4+5"));
+}
+
+TEST(DiceIO, StringFormDoesNotPreserveWhitespace) {
   std::stringstream ss;
   ss << dice::from_string("2 { d 4 + 5 }");
   EXPECT_THAT(ss.str(), Eq("2{1d4+5}"));