Skip to content

Commit e373e7f

Browse files
committed
Add base64 test
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent c173f9f commit e373e7f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

.github/workflows/pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ jobs:
2828
2929
# Run unit tests
3030
RESOURCES_PATH=test/resources build/sentencepiece_test
31+
build/tiktoken_test

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@ if(TOKENIZERS_BUILD_TEST)
5353
sentencepiece_test PUBLIC third-party/sentencepiece/src
5454
third-party/sentencepiece include GTEST_INCLUDE_PATH)
5555
target_link_libraries(sentencepiece_test PUBLIC tokenizers gtest_main)
56+
57+
# tiktoken tests
58+
add_executable(tiktoken_test test/test_base64.cpp)
59+
target_include_directories(tiktoken_test PUBLIC include GTEST_INCLUDE_PATH)
60+
target_link_libraries(tiktoken_test PUBLIC gtest_main)
5661
endif()

test/test_base64.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include "base64.h"
10+
#include "gtest/gtest.h"
11+
12+
namespace tokenizers {
13+
14+
TEST(Base64Test, TestDecodeSmoke) {
15+
std::string text = "bGxhbWE=";
16+
auto result = base64::decode(text);
17+
EXPECT_TRUE(result.ok());
18+
EXPECT_EQ(result.get(), "llama");
19+
}
20+
21+
TEST(Base64Test, TestDecodeEmptyStringReturnsError) {
22+
std::string text = "";
23+
auto result = base64::decode(text);
24+
EXPECT_FALSE(result.ok());
25+
EXPECT_EQ(result.error(), Error::Base64DecodeFailure);
26+
}
27+
28+
TEST(Base64Test, TestInvalidStringDecodeReturnsError) {
29+
std::string text = "llama";
30+
auto result = base64::decode(text);
31+
EXPECT_FALSE(result.ok());
32+
EXPECT_EQ(result.error(), Error::Base64DecodeFailure);
33+
}
34+
35+
} // namespace tokenizers

0 commit comments

Comments
 (0)