Skip to content

Commit

Permalink
Adding a begin iterator to the ValueStack.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Sep 11, 2023
1 parent f035ef0 commit 8c583c4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.1
6.2.1
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_google_googletest",
urls = ["https://github.com/google/googletest/archive/d166e09483845b9b6a658dccc3d3dbb293676b62.zip"],
strip_prefix = "googletest-d166e09483845b9b6a658dccc3d3dbb293676b62",
sha256 = "d27641a853c49d3e8d7b9bbced1ceb861336134cd148bf6db720a40ccde66516",
urls = ["https://github.com/google/googletest/archive/8a6feabf04bec8fb125e0df0ad1195c42350725f.zip"],
strip_prefix = "googletest-8a6feabf04bec8fb125e0df0ad1195c42350725f",
sha256 = "c83f69fa8cb7a503d3ae9f736cf679b0846772b1ae955c63133520b749491a7c",
)

http_archive(
Expand Down
1 change: 1 addition & 0 deletions jasmin/value_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct ValueStack {
using const_iterator = Value const *;

// Returns an iterator referrencing one passed the end. of the `ValueStack`.
const_iterator begin() const { return values_.get(); }
const_iterator end() const { return head_; }

// Pop the top `Value` off the stack and return it. Behavior is undefined if
Expand Down
10 changes: 10 additions & 0 deletions jasmin/value_stack_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ TEST(ValueStack, Erase) {
#endif // defined(JASMIN_DEBUG)
}

TEST(ValueStack, Begin) {
ValueStack value_stack{1, true, 3.14};
EXPECT_EQ((value_stack.begin() + 2)->as<double>(), 3.14);
EXPECT_EQ((value_stack.begin() + 1)->as<bool>(), true);
EXPECT_EQ((value_stack.begin())->as<int>(), 1);
value_stack.pop_value();
EXPECT_EQ((value_stack.begin() + 2)->as<bool>(), true);
EXPECT_EQ((value_stack.begin() + 1)->as<int>(), 1);
}

TEST(ValueStack, End) {
ValueStack value_stack{1, true, 3.14};
EXPECT_EQ((value_stack.end() - 1)->as<double>(), 3.14);
Expand Down

0 comments on commit 8c583c4

Please sign in to comment.