Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve macro handling of McBopomofoLM and expand test coverage #133

Merged
merged 6 commits into from
Mar 15, 2024

Conversation

lukhnos
Copy link
Collaborator

@lukhnos lukhnos commented Mar 15, 2024

After this PR, every class in Engine/ will have a test.

Other than that, two notable changes:

  1. We now disallow copying and/or moving from many classes, therefore eliminating a source of potential mistakes.
  2. If a macro (such as MACRO@DATE_TODAY_SHORT) is not handled by the macro converter, we discard the unigram value. This actually implies that it's no longer critical to ensure macros are supported across the board (see Ensure macros in McBopomofo macOS and fcitx5-mcbopomofo are in sync #100), as macros not supported/implemented on one platform will simply not be shown as MACRO@FOOBAR in the candidate list. @zonble FYI.

I also used the opportunity to audit our mmap and std::string_view uses, and have clarified the mmap contract—we map a readable, shared page, but MemoryMappedFile class itself does not track and won't be aware of file changes. Not that it would affect McBopomofo's existing behavior, but it's good to state the contract more explicitly.

@lukhnos lukhnos requested review from zonble and tianjianjiang March 15, 2024 03:16
@lukhnos lukhnos changed the title [DO NOT MERGE] Improve test coverage and macro handling of McBopomofoLM and other engine classes [DO NOT MERGE] Improve test coverage and macro handling of McBopomofoLM Mar 15, 2024
@lukhnos lukhnos changed the title [DO NOT MERGE] Improve test coverage and macro handling of McBopomofoLM [DO NOT MERGE] Improve macro handling of McBopomofoLM and expand test coverage Mar 15, 2024
@tianjianjiang
Copy link
Member

@lukhnos @zonble Let me convert this to draft so it won't be merged accidentally.

@tianjianjiang tianjianjiang marked this pull request as draft March 15, 2024 03:32
lukhnos added 5 commits March 15, 2024 05:06
- Allow loading existing in-memory data.
- Improve tests.
- Disallow copying and moving.
- Clearly state that MemoryMappedFile does not manage underlying file
  changes.
- Clearly state that if an existing block of data is used for load() in
  PhraseReplacementMap or UserPhrasesLM, it is the caller's
  responsibility to ensure that the data outlives the LM object.
- Removes macro values not handled by the macro converter
- Reformats and clarifies McBopomofoLM comments
- Rearranges the order of member functions
- Adds tests
@lukhnos lukhnos force-pushed the dev/lm-test-coverage branch from e89d074 to 1545e23 Compare March 15, 2024 12:06
@lukhnos lukhnos changed the base branch from dev/merge-pr-131-and-132 to master March 15, 2024 12:06
@lukhnos lukhnos changed the title [DO NOT MERGE] Improve macro handling of McBopomofoLM and expand test coverage Improve macro handling of McBopomofoLM and expand test coverage Mar 15, 2024
@lukhnos lukhnos marked this pull request as ready for review March 15, 2024 12:07
Copy link
Collaborator

@zonble zonble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I did not find any impact since the PR only adds tests.

@zonble zonble merged commit 8172a09 into master Mar 15, 2024
6 checks passed
@lukhnos lukhnos deleted the dev/lm-test-coverage branch March 15, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants