{"id":21257802,"url":"https://github.com/maroontress/lighter","last_synced_at":"2025-08-20T18:10:33.891Z","repository":{"id":103784529,"uuid":"483237516","full_name":"maroontress/lighter","owner":"maroontress","description":"Lighter is a header-only library in C++20 to check assertions.","archived":false,"fork":false,"pushed_at":"2023-07-30T17:10:20.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T04:36:25.654Z","etag":null,"topics":["assertion-library","cplusplus-20","header-only-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maroontress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-19T12:29:49.000Z","updated_at":"2023-07-16T17:17:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"0c5e03bb-0fea-4876-97a5-b1a10384e05b","html_url":"https://github.com/maroontress/lighter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/maroontress/lighter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maroontress%2Flighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maroontress%2Flighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maroontress%2Flighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maroontress%2Flighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maroontress","download_url":"https://codeload.github.com/maroontress/lighter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maroontress%2Flighter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271362128,"owners_count":24746496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assertion-library","cplusplus-20","header-only-library"],"created_at":"2024-11-21T04:05:55.368Z","updated_at":"2025-08-20T18:10:33.826Z","avatar_url":"https://github.com/maroontress.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lighter\n\nLighter is a header-only library in C++20 to check assertions.\n\n## Examples\n\nIn preparation, define the macro `expect(x)` as follows:\n\n```c++\n#define expect(x) maroontress::lighter::Flint {(x), #x, [](auto r) { \\\n        const auto\u0026 w = std::source_location::current(); \\\n        std::cout \\\n            \u003c\u003c w.file_name() \u003c\u003c \":\" \u003c\u003c w.line() \u003c\u003c \": error:\" \u003c\u003c std::endl \\\n            \u003c\u003c \"  Expected: \" \u003c\u003c r.getExpected() \u003c\u003c std::endl \\\n            \u003c\u003c \"  Actual:   \" \u003c\u003c r.getActual() \u003c\u003c std::endl; \\\n    }}\n```\n\nThe macro `expect(x)` is a trigger to start an assertion, and when the\nassertion fails, it calls the lambda expression at the third argument with the\nreason for the assertion failure. Note that the macro name `expect` is used\nonly to illustrate the following examples and can be any name.\n\n### Integers\n\nHere is a simple example of using the macro `expect(x)`:\n\n```c++\nint x {12};\n\n// PASS\nexpect(x) == 12;\n\n// FAIL\nexpect(x) == 13;\n```\n\nThe first assertion `expect(x) == 12;` does nothing because the variable `x` is\n12. On the other hand, the second `expect(x) != 12;` fails so that it calls\nthe lambda expression and then prints as follows:\n\n```plaintext\nmain.cxx:14: error:\n  Expected: x == 13\n  Actual:   x was 12\n```\n\nIn addition to `==`, you can also use `!=`, `\u003c`, `\u003e`, `\u003c=`, and `\u003e=` as\noperators. Note that the expression `expect(x)` itself does nothing. Comparison\nwith an operator triggers an evaluation.\n\n### Pointers\n\nFor pointers, the member functions `isNull()` and `isNotNull()` are available to\ncompare the specified value with `nullptr` as follows:\n\n```c++\nint x {12};\n\n// PASS\nexpect(\u0026x) != nullptr;\nexpect(\u0026x).isNotNull();\n\n// FAIL\nexpect(\u0026x) == nullptr;\nexpect(\u0026x).isNull();\n```\n\nThe last two assertions fail and the console shows:\n\n```plaintext\nmain.cxx:26: error:\n  Expected: \u0026x == nullptr\n  Actual:   \u0026x was 0xafc178f4a4\nmain.cxx:27: error:\n  Expected: \u0026x is null\n  Actual:   \u0026x was 0xafc178f4a4\n```\n\n### Booleans\n\nFor booleans, the member functions `isTrue()` and `isFalse()` are available:\n\n```c++\nbool x {false};\n\n// PASS\nexpect(x).isFalse();\n\n// FAIL\nexpect(x).isTrue();\n```\n\nThe last assertion fails and the console shows:\n\n```plaintext\nmain.cxx:38: error:\n  Expected: x is true\n  Actual:   x was false\n```\n\n### Containers\n\nLet's look at more complex use cases. For containers, the following member\nfunctions are available:\n\n- `size()`\n- `anyItem()`\n- `everyItem()`\n\nThe function `size()` transforms the container to its size as follows:\n\n```c++\nstd::vector\u003cint\u003e x {12, 23, 34};\nstd::initializer_list\u003cstd::string\u003e y = {\"a\", \"b\"};\n\n// PASS\nexpect(x).size() == 3;\nexpect(y).size() == 2;\n\n// FAIL\nexpect(x).size() == 1;\nexpect(y).size() == 0;\n```\n\nThe last two assertions fail and the console shows:\n\n```plaintext\nmain.cxx:51: error:\n  Expected: the size of (x) == 1\n  Actual:   the size of (x) was 3\nmain.cxx:52: error:\n  Expected: the size of (y) == 0\n  Actual:   the size of (y) was 2\n```\n\nThe function `anyItem()` transforms the container to its elements. The\nassertion fails only when none of them meets the requirement on the right-hand\nside of `anyItem()`.\n\n```c++\nstd::vector\u003cint\u003e x {12, 23, 34};\nstd::initializer_list\u003cstd::string\u003e y = {\"a\", \"b\"};\n\n// PASS\nexpect(x).anyItem() == 23;\nexpect(y).anyItem() == \"a\";\n\n// FAIL\nexpect(x).anyItem() \u003e 45;\nexpect(y).anyItem() == \"c\";\n```\n\nThe last two assertions fail and the console shows:\n\n```plaintext\nmain.cxx:65: error:\n  Expected: any element of (x) \u003e 45\n  Actual:   none of the elements met that requirement\nmain.cxx:66: error:\n  Expected: any element of (y) == \"c\"\n  Actual:   none of the elements met that requirement\n```\n\nThe function `everyItem()` also transforms the container to its elements.\nHowever, the assertion fails when at least one of them does not meet the\nrequirement on the right-hand side of `everyItem()`.\n\n```c++\nstd::vector\u003cint\u003e x {12, 23, 34};\nstd::initializer_list\u003cstd::string\u003e y = {\"a\", \"b\"};\n\n// PASS\nexpect(x).everyItem() \u003c 45;\nexpect(y).everyItem() \u003c= \"b\";\n\n// FAIL\nexpect(x).everyItem() \u003c 20;\nexpect(y).everyItem() == \"b\";\n```\n\nThe last two assertions fail and the console shows:\n\n```plaintext\nmain.cxx:79: error:\n  Expected: every element of (x) \u003c 20\n  Actual:   (x)[1] was 23\nmain.cxx:80: error:\n  Expected: every element of (y) == \"b\"\n  Actual:   (y)[0] was \"a\"\n```\n\nIf the container is empty, the behavior of `anyItem()` and `everyItem()` is\nquite different. For empty containers, the `anyItem()` always fails, while\n`everyItem()` always succeeds as follows:\n\n```c++\nstd::vector\u003cint\u003e z {};\n\n// PASS\nexpect(z).everyItem() == 10;\n\n// FAIL\nexpect(z).anyItem() == 10;\n```\n\nThe last assertion fails and the console shows:\n\n```plaintext\nmain.cxx:91: error:\n  Expected: any element of (z) == 10\n  Actual:   there is no element\n```\n\nNote that `size()`, `anyItem()`, and `everyItem()` can be combined as follows:\n\n```c++\nstd::vector\u003cstd::string\u003e a = {\"aaa\"}, b = {\"bb\", \"bbb\"}, c = {\"c\", \"cc\"};\nauto x = {a, b, c};\n\n// PASS\nexpect(x).anyItem().everyItem().size() \u003e 2;\n\n// FAIL\nexpect(x).everyItem().anyItem().size() \u003e 2;\n```\n\nThe last assertion fails and the console shows:\n\n```plaintext\nmain.cxx:103: error:\n  Expected: the size of (any element of (every element of (x))) \u003e 2\n  Actual:   as for (x)[2], none of the elements met that requirement\n```\n\n\u003e [Run all examples](https://replit.com/@maroontress/cxx20-lighter#main.cxx)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaroontress%2Flighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaroontress%2Flighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaroontress%2Flighter/lists"}