Skip to content

Commit

Permalink
Merge pull request #146 from zonble/master
Browse files Browse the repository at this point in the history
Fixes the issue that the Chinese number module does not correctly handle zero.
  • Loading branch information
lukhnos authored Jul 30, 2024
2 parents 916e7fd + 9523785 commit 05f4544
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@ name: CI
on: [push, pull_request]

jobs:
build_ubuntu_24:
runs-on: ubuntu-latest
container: ubuntu:24.04

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt install -y pkg-config
apt install -y clang
apt install -y cmake extra-cmake-modules gettext libfmt-dev
apt install -y fcitx5 libfcitx5core-dev libfcitx5config-dev libfcitx5utils-dev fcitx5-modules-dev
apt install -y libjson-c-dev
- name: Build
run: |
mkdir -p build
cd build
cmake ../ -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug
make -j
cd ../
mkdir -p src/Engine/build
cd src/Engine/build
cmake ../
make -j
- name: Test
run: |
cd build
ctest --output-on-failure
build_ubuntu_22:
runs-on: ubuntu-latest
container: ubuntu:22.04
Expand Down
6 changes: 5 additions & 1 deletion src/ChineseNumbers/ChineseNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ std::string ChineseNumbers::Generate(const std::string& intPart,

std::stringstream output;
if (intTrimmed.empty()) {
output << "0";
if (digitCase == ChineseNumbers::ChineseNumberCase::LOWERCASE) {
output << kLowerDigits[0];
} else if (digitCase == ChineseNumbers::ChineseNumberCase::UPPERCASE) {
output << kUpperDigits[0];
}
} else {
size_t intSectionCount = static_cast<size_t>(
ceil(static_cast<double>(intTrimmed.length()) / 4.0));
Expand Down
12 changes: 12 additions & 0 deletions src/ChineseNumbers/ChineseNumbersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
#include "ChineseNumbers.h"
#include "gtest/gtest.h"

TEST(ChineseNumberTest, Test0_lower) {
std::string output = ChineseNumbers::Generate(
"0000", "0", ChineseNumbers::ChineseNumberCase::LOWERCASE);
EXPECT_EQ(output, "");
}

TEST(ChineseNumberTest, Test0_uipper) {
std::string output = ChineseNumbers::Generate(
"0000", "0", ChineseNumbers::ChineseNumberCase::UPPERCASE);
EXPECT_EQ(output, "");
}

TEST(ChineseNumberTest, Test1) {
std::string output = ChineseNumbers::Generate(
"0001", "0", ChineseNumbers::ChineseNumberCase::LOWERCASE);
Expand Down

0 comments on commit 05f4544

Please sign in to comment.