// IACore-OSS; The Core Library for All IA Open Source Projects // Copyright (C) 2026 IAS (ias@iasoft.dev) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include #include using namespace IACore; // ----------------------------------------------------------------------------- // Test Block Definition // ----------------------------------------------------------------------------- IAT_BEGIN_BLOCK(Core, CLI) // ------------------------------------------------------------------------- // 1. Basic Traversal // ------------------------------------------------------------------------- auto test_basic_traversal() -> bool { const Vec args = {"ignored", "one", "two", "three"}; CLIParser parser(args); IAT_CHECK(parser.remaining()); // Check sequential access IAT_CHECK_EQ(String(parser.next()), "one"); IAT_CHECK(parser.remaining()); IAT_CHECK_EQ(String(parser.next()), "two"); IAT_CHECK(parser.remaining()); IAT_CHECK_EQ(String(parser.next()), "three"); // Should be exhausted now IAT_CHECK_NOT(parser.remaining()); // Next on exhausted returns empty string view IAT_CHECK_EQ(String(parser.next()), ""); return true; } // ------------------------------------------------------------------------- // 2. Peek Functionality // ------------------------------------------------------------------------- auto test_peek() -> bool { const Vec args = {"ignored", "peek_val", "next_val"}; CLIParser parser(args); // Peek should return value but not advance IAT_CHECK_EQ(String(parser.peek()), "peek_val"); IAT_CHECK(parser.remaining()); // Verify we are still at the same element IAT_CHECK_EQ(String(parser.next()), "peek_val"); // Now we should be at next_val IAT_CHECK_EQ(String(parser.peek()), "next_val"); IAT_CHECK_EQ(String(parser.next()), "next_val"); IAT_CHECK_NOT(parser.remaining()); return true; } // ------------------------------------------------------------------------- // 3. Consume Functionality // ------------------------------------------------------------------------- auto test_consume() -> bool { const Vec args = {"ignored", "-v", "--output", "file.txt"}; CLIParser parser(args); // 1. Try consuming something that isn't there IAT_CHECK_NOT(parser.consume("-x")); // Verify we haven't moved IAT_CHECK_EQ(String(parser.peek()), "-v"); // 2. Consume the correct flag IAT_CHECK(parser.consume("-v")); // 3. Verify advancement IAT_CHECK_EQ(String(parser.peek()), "--output"); // 4. Consume next IAT_CHECK(parser.consume("--output")); // 5. Verify final argument IAT_CHECK_EQ(String(parser.next()), "file.txt"); IAT_CHECK_NOT(parser.remaining()); return true; } // ------------------------------------------------------------------------- // 4. Empty Argument List // ------------------------------------------------------------------------- auto test_empty() -> bool { const Vec args = {}; CLIParser parser(args); IAT_CHECK_NOT(parser.remaining()); IAT_CHECK_EQ(String(parser.peek()), ""); IAT_CHECK_EQ(String(parser.next()), ""); IAT_CHECK_NOT(parser.consume("-help")); return true; } // ------------------------------------------------------------------------- // Registration // ------------------------------------------------------------------------- IAT_BEGIN_TEST_LIST() IAT_ADD_TEST(test_basic_traversal); IAT_ADD_TEST(test_peek); IAT_ADD_TEST(test_consume); IAT_ADD_TEST(test_empty); IAT_END_TEST_LIST() IAT_END_BLOCK() IAT_REGISTER_ENTRY(Core, CLI)