Skip to content

Commit

Permalink
feat: add usage
Browse files Browse the repository at this point in the history
Signed-off-by: Dup4 <[email protected]>
  • Loading branch information
Dup4 committed Sep 17, 2023
1 parent 61c4f44 commit 41d1146
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"clangd.arguments": [
"--compile-commands-dir=./",
"--compile-commands-dir=./build",
"--background-index",
"--header-insertion=iwyu",
"--all-scopes-completion",
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ Similar to [Jest Snapshot][jest-snapshot], but implemented in C++.
* `SNAPSHOT_DIFF(before_content, after_content)` required `git` binary.
* Support Linux and macOS.

## Usage

```cpp
const std::string tmp = "snapshot-cpp";
const std::string tmp_diff = tmp + "-diff";

EXPECT_EQ(tmp, SNAPSHOT_INLINE(tmp));
// EXPECT_EQ(tmp, std::string("snapshot-cpp"));

SNAPSHOT(tmp);
// // /home/Dup4/snapshot-cpp/test/snapshot_test.cc.TestBody.58.0
// std::string("snapshot-cpp")

SNAPSHOT_DIFF(tmp, tmp_diff);
// // /home/Dup4/snapshot-cpp/test/snapshot_test.cc.TestBody.59.0
// // before
// std::string("snapshot-cpp")
// // after
// std::string("snapshot-cpp-diff")
// // diff
// diff --git a/tmp/snapshot_test.cc.TestBody.59.0.snap.before b/tmp/snapshot_test.cc.TestBody.59.0.snap.after
// index aeb786e..3982900 100644
// --- a/tmp/snapshot_test.cc.TestBody.59.0.snap.before
// +++ b/tmp/snapshot_test.cc.TestBody.59.0.snap.after
// @@ -1 +1 @@
// -std::string("snapshot-cpp")
// \ No newline at end of file
// +std::string("snapshot-cpp-diff")
// \ No newline at end of file
```
[clang-format-badge]: https://github.com/Dup4/snapshot-cpp/workflows/Clang%20Format/badge.svg
[clang-format-action]: https://github.com/Dup4/snapshot-cpp/actions/workflows/clang_format.yml
[test-badge]: https://github.com/Dup4/snapshot-cpp/workflows/Test/badge.svg
Expand Down
9 changes: 9 additions & 0 deletions test/snapshot_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ TEST_F(SnapshotTest, get_snapshot_inline_match_range) {
EXPECT_EQ(SnapshotTest::getSnapshotInlineMatchRange("SNAPSHOT_INLINE(\")\")"), make_pair(0, 17));
}

TEST_F(SnapshotTest, README) {
const std::string tmp = "snapshot-cpp";
const std::string tmp_diff = tmp + "-diff";

EXPECT_EQ(tmp, std::string("snapshot-cpp"));
SNAPSHOT(tmp);
SNAPSHOT_DIFF(tmp, tmp_diff);
}

} // namespace snapshot

0 comments on commit 41d1146

Please sign in to comment.