-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2020 Arduino. All rights reserved. | ||
*/ | ||
|
||
/************************************************************************************** | ||
* INCLUDE | ||
**************************************************************************************/ | ||
|
||
#include <catch.hpp> | ||
|
||
#include <MillisFake.h> | ||
#include <StreamMock.h> | ||
|
||
/************************************************************************************** | ||
* TEST CODE | ||
**************************************************************************************/ | ||
|
||
TEST_CASE ("Testing 'Format' initialisation", "[Stream-insertion-operator-01]") { | ||
Format<char> fmt {'a', 2}; | ||
REQUIRE(fmt.data == 'a'); | ||
REQUIRE(fmt.modifier == 2); | ||
} | ||
|
||
TEST_CASE ("Testing 'format' helper function", "[Stream-insertion-operator-02]") { | ||
Format<char> fmt {format('a', 2)}; | ||
REQUIRE(fmt.data == 'a'); | ||
REQUIRE(fmt.modifier == 2); | ||
} | ||
|
||
TEST_CASE ("Testing basic insertion operator", "[Stream-insertion-operator-03]") { | ||
StreamMock mock; | ||
mock << 'a' << 12 << 'b' << 34; // Note we cannot test C strings as `StreamMock` has its own << operator. | ||
REQUIRE(mock.available() == 6); | ||
} | ||
|
||
TEST_CASE ("Testing insertion operator with modifiers", "[Stream-insertion-operator-03]") { | ||
StreamMock mock; | ||
mock << format(1.2, 4); // Expands to `1.2000`. | ||
REQUIRE(mock.available() == 6); | ||
mock << format(12, BIN); // Expands to `1100`. | ||
REQUIRE(mock.available() == 10); | ||
} |