// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]tundra/unittest/test_PathUtil.cpp
// Function: PathUtil_Init_Test::TestBody()
TEST(PathUtil, Init)
{
  static const struct
  {
    PathType::Enum  type;
    const char     *input;
    const char     *expected_output;
    bool            expect_absolute;
    int             expect_segs;
    int             expect_seg_lens[8];
  }
  test_data[] =
  {
    { PathType::kUnix, "",                "",                     false,  0, {} },
    { PathType::kUnix, "/",               "/",                    true,   0, {} },
    { PathType::kUnix, "////",            "/",                    true,   0, {} },
    { PathType::kUnix, "foo.c",           "foo.c",                false,  1, { 5 } },
    { PathType::kUnix, "/foo.c",          "/foo.c",               true,   1, { 5 } },
    { PathType::kUnix, "foo/bar.c",       "foo/bar.c",            false,  2, { 3, 5 } },
    { PathType::kUnix, "/foo/bar.c",      "/foo/bar.c",           true,   2, { 3, 5 } },
    { PathType::kUnix, "/foo///bar.c",    "/foo/bar.c",           true,   2, { 3, 5 } },
    { PathType::kUnix, "/foo///bar.c/",   "/foo/bar.c",           true,   2, { 3, 5 } },
    { PathType::kUnix, "/foo/./bar.c/",   "/foo/bar.c",           true,   2, { 3, 5 } },
    { PathType::kUnix, "/foo/../bar.c/",  "/bar.c",               true,   1, { 5 } },
    { PathType::kUnix, "foo/../../bar.c", "../bar.c",             false,  1, { 5 } },
    { PathType::kUnix, "../../../bar.c",  "../../../bar.c",       false,  1, { 5 } },
    { PathType::kUnix, "./././bar.c",     "bar.c",                false,  1, { 5 } },
    { PathType::kUnix, ".",               "",                     false,  0, {}},
    { PathType::kUnix, "././.",           "",                     false,  0, {}},

    { PathType::kWindows, "",                "",                     false,  0, {} },
    { PathType::kWindows, "\\",              "\\",                   true,   0, {} },
    { PathType::kWindows, "////",            "\\",                   true,   0, {} },
    { PathType::kWindows, "foo.c",           "foo.c",                false,  1, { 5 } },
    { PathType::kWindows, "/foo.c",          "\\foo.c",              true,   1, { 5 } },
    { PathType::kWindows, "foo/bar.c",       "foo\\bar.c",           false,  2, { 3, 5 } },
    { PathType::kWindows, "/foo/bar.c",      "\\foo\\bar.c",         true,   2, { 3, 5 } },
    { PathType::kWindows, "/foo///bar.c",    "\\foo\\bar.c",         true,   2, { 3, 5 } },
    { PathType::kWindows, "/foo///bar.c/",   "\\foo\\bar.c",         true,   2, { 3, 5 } },
    { PathType::kWindows, "/foo/./bar.c/",   "\\foo\\bar.c",         true,   2, { 3, 5 } },
    { PathType::kWindows, "/foo/../bar.c/",  "\\bar.c",              true,   1, { 5 } },
    { PathType::kWindows, "foo/../../bar.c", "..\\bar.c",            false,  1, { 5 } },
    { PathType::kWindows, "../../../bar.c",  "..\\..\\..\\bar.c",    false,  1, { 5 } },
    { PathType::kWindows, "./././bar.c",     "bar.c",                false,  1, { 5 } },
    { PathType::kWindows, ".",               "",                     false,  0, { } },
    { PathType::kWindows, "././.",           "",                     false,  0, { } },
    { PathType::kWindows, "x:\\foo",         "x:\\foo",              true,   2, { 2, 3 } },
    { PathType::kWindows, "x:/foo",          "x:\\foo",              true,   2, { 2, 3 } },
  };

  for (size_t i = 0; i < ARRAY_SIZE(test_data); ++i)
  {
    PathBuffer path;
    PathInit(&path, test_data[i].input, test_data[i].type);
    ASSERT_EQ(test_data[i].expect_absolute, PathIsAbsolute(&path));
    ASSERT_EQ(test_data[i].expect_segs, path.m_SegCount);

    for (int s = 0; s < path.m_SegCount; ++s)
    {
      ASSERT_EQ(test_data[i].expect_seg_lens[s], path.SegLength(s));
    }

    char buffer[kMaxPathLength];
    PathFormat(buffer, &path);
    ASSERT_STREQ(test_data[i].expected_output, buffer);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4c8, %rsp            # imm = 0x4C8
leaq 0x38(%rsp), %rbx
leaq 0x365db(%rip), %rax     # 0x67ce0
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
leaq 0x365ac(%rip), %r14     # 0x67cc0
leaq 0x30(%rsp), %r12
leaq 0x8(%rsp), %r13
cmpq $0x22, %r15
je 0x318f6
movq %r15, 0x28(%rsp)
shlq $0x6, %r15
leaq (%r15,%r14), %rbp
addq $0x18, %rbp
movq -0x10(%rbp), %rsi
movl -0x18(%rbp), %edx
leaq 0x23c(%rsp), %rdi
callq 0x351c8
movb 0x240(%rsp), %al
andb $0x1, %al
movb %al, 0x8(%rsp)
movq %r12, %rdi
leaq 0x16a27(%rip), %rsi     # 0x4818b
leaq 0x16a3d(%rip), %rdx     # 0x481a8
movq %rbp, %rcx
movq %r13, %r8
callq 0x2b0f9
cmpb $0x0, 0x30(%rsp)
je 0x31908
addq %r14, %r15
movq %rbx, %rdi
callq 0x2295e
leaq 0x1c(%r15), %rcx
movq %r12, %rdi
leaq 0x16a24(%rip), %rsi     # 0x481be
leaq 0x16a36(%rip), %rdx     # 0x481d7
leaq 0x242(%rsp), %r8
callq 0x31c93
cmpb $0x0, 0x30(%rsp)
je 0x31921
leaq 0x38(%rsp), %rdi
callq 0x2295e
movq 0x20(%rsp), %rbp
xorl %r14d, %r14d
leaq 0x16a35(%rip), %rbx     # 0x48207
movzwl 0x242(%rsp), %eax
cmpq %rax, %r14
jae 0x31837
testq %r14, %r14
je 0x317f8
movzwl 0x246(%rsp,%r14,2), %eax
subw 0x244(%rsp,%r14,2), %ax
jmp 0x31800
movzwl 0x246(%rsp), %eax
movw %ax, 0x8(%rsp)
movq %r12, %rdi
leaq 0x169d8(%rip), %rsi     # 0x481e7
movq %rbx, %rdx
movq %rbp, %rcx
movq %r13, %r8
callq 0x31c93
cmpb $0x0, 0x30(%rsp)
je 0x31898
leaq 0x38(%rsp), %rdi
callq 0x2295e
incq %r14
addq $0x4, %rbp
jmp 0x317d2
movq %r12, %rdi
leaq 0x23c(%rsp), %rsi
callq 0x3553e
movq 0x10(%r15), %rcx
movq %r13, %rdi
leaq 0x169c4(%rip), %rsi     # 0x48219
leaq 0x18239(%rip), %rdx     # 0x49a95
movq %r12, %r8
callq 0x13723
cmpb $0x0, 0x8(%rsp)
je 0x3193a
leaq 0x10(%rsp), %rdi
callq 0x2295e
movq 0x28(%rsp), %r15
incq %r15
addq $0x40, 0x20(%rsp)
leaq 0x38(%rsp), %rbx
leaq 0x3642d(%rip), %r14     # 0x67cc0
jmp 0x3171e
leaq 0x8(%rsp), %rdi
callq 0x11c8e
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x318b1
movq (%rax), %r8
jmp 0x318b8
leaq 0x185ef(%rip), %r8      # 0x49ea7
leaq 0x16809(%rip), %rdx     # 0x480c8
movq %rsp, %rdi
pushq $0x2
popq %rsi
pushq $0x41
popq %rcx
callq 0x104f8
movq %rsp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x10576
movq %rsp, %rdi
callq 0x10558
leaq 0x8(%rsp), %rdi
callq 0x1f8e0
leaq 0x38(%rsp), %rdi
callq 0x2295e
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rdi
callq 0x11c8e
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x31951
movq (%rax), %r8
jmp 0x31958
leaq 0x8(%rsp), %rdi
callq 0x11c8e
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x31994
movq (%rax), %r8
jmp 0x3199b
movq %rsp, %rdi
callq 0x11c8e
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x319c2
movq (%rax), %r8
jmp 0x319c9
leaq 0x1854f(%rip), %r8      # 0x49ea7
leaq 0x16769(%rip), %rdx     # 0x480c8
movq %rsp, %rdi
pushq $0x2
popq %rsi
pushq $0x3c
popq %rcx
callq 0x104f8
movq %rsp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x10576
movq %rsp, %rdi
callq 0x10558
leaq 0x8(%rsp), %rdi
callq 0x1f8e0
movq %rbx, %rdi
jmp 0x318f1
leaq 0x1850c(%rip), %r8      # 0x49ea7
leaq 0x16726(%rip), %rdx     # 0x480c8
movq %rsp, %rdi
pushq $0x2
popq %rsi
pushq $0x3d
popq %rcx
callq 0x104f8
movq %rsp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x10576
jmp 0x318da
leaq 0x184de(%rip), %r8      # 0x49ea7
leaq 0x166f8(%rip), %rdx     # 0x480c8
leaq 0x18(%rsp), %rdi
pushq $0x2
popq %rsi
pushq $0x46
popq %rcx
callq 0x104f8
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
callq 0x10576
leaq 0x18(%rsp), %rdi
callq 0x10558
movq %rsp, %rdi
callq 0x1f8e0
leaq 0x10(%rsp), %rdi
jmp 0x318f1
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x10558
jmp 0x31a1b
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1f8e0
jmp 0x31a28
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x31a5f
jmp 0x31a3b
jmp 0x31a48
jmp 0x31a57
jmp 0x31a3b
jmp 0x31a48
jmp 0x31a57
movq %rax, %rbx
movq %rsp, %rdi
callq 0x10558
jmp 0x31a4b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1f8e0
jmp 0x31a5a
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2295e
movq %rbx, %rdi
callq 0xdbf0