diff --git a/.vscode/settings.json b/.vscode/settings.json index 6d14e92..fb7e7b0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", diff --git a/README.md b/README.md index 7a1e78f..7befcd0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test/snapshot_test.cc b/test/snapshot_test.cc index 1c299dd..1cec031 100644 --- a/test/snapshot_test.cc +++ b/test/snapshot_test.cc @@ -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