def test_basic_replace(self):
        write_file(
            "foo.thrift",
            textwrap.dedent(
                """\
                struct Faa {
                    1: i32 faa1;
                    2: optional Faa faa2 (cpp.ref);
                    3: i32 faa3;
                }
                """
            ),
        )

        run_binary("cppref_to_structured", "foo.thrift")

        # NOTE: For current tests, user should rely on automated formatting.
        self.assertEqual(
            read_file("foo.thrift"),
            textwrap.dedent(
                """\
                include "thrift/annotation/cpp.thrift"
                struct Faa {
                    1: i32 faa1;
                    @cpp.Ref{type = cpp.RefType.Unique}
                2: optional Faa faa2 ;
                    3: i32 faa3;
                }
                """
            ),
        )
    def test_namespaces(self):
        write_file(
            "foo.thrift",
            textwrap.dedent(
                """\
                namespace cpp2 apache.thrift
                namespace py3 thrift.lib.thrift
                struct Faa {
                    1: i32 faa1;
                    2: optional Faa faa2 (cpp.ref);
                    3: i32 faa3;
                }
                """
            ),
        )

        run_binary("cppref_to_structured", "foo.thrift")

        self.assertEqual(
            read_file("foo.thrift"),
            textwrap.dedent(
                """\
                namespace cpp2 apache.thrift
                namespace py3 thrift.lib.thrift
                struct Faa {
                    1: i32 faa1;
                    2: optional Faa faa2 (cpp.ref);
                    3: i32 faa3;
                }
                """
            ),
        )
    def test_cpp_and_cpp2(self):
        write_file(
            "foo.thrift",
            textwrap.dedent(
                """\
                struct Faa {
                    1: i32 faa1;
                    2: optional Faa faa2 (cpp.ref = "true", cpp2.ref = "true");
                    3: i32 faa3;
                }
                """
            ),
        )

        run_binary("cppref_to_structured", "foo.thrift")

        self.assertEqual(
            read_file("foo.thrift"),
            textwrap.dedent(
                """\
                include "thrift/annotation/cpp.thrift"
                struct Faa {
                    1: i32 faa1;
                    @cpp.Ref{type = cpp.RefType.Unique}
                2: optional Faa faa2 ;
                    3: i32 faa3;
                }
                """
            ),
        )
    def test_basic_remove(self):
        write_file(
            "foo.thrift",
            textwrap.dedent("""\
                struct Faa {
                    1: i32 faa1;
                    2: string faa2;
                } (cpp.noexcept_move, cpp.virtual)

                union Fee {
                    1: i32 fee1;
                    2: string fee2;
                } (cpp.noexcept_move)
                """),
        )

        run_binary("remove_cpp_noexcept_move", "foo.thrift")

        self.assertEqual(
            read_file("foo.thrift"),
            textwrap.dedent("""\
                struct Faa {
                    1: i32 faa1;
                    2: string faa2;
                } ( cpp.virtual)

                union Fee {
                    1: i32 fee1;
                    2: string fee2;
                } 
                """),
        )
    def test_existing_includes(self):
        write_file("a.thrift", "")
        write_file("b.thrift", "")
        write_file("c.thrift", "")

        write_file(
            "foo.thrift",
            textwrap.dedent(
                """\
                include "a.thrift"
                include "b.thrift"
                include "c.thrift"

                struct Faa {
                    1: i32 faa1;
                    2: optional Faa faa2 (cpp.ref);
                    3: i32 faa3;
                }
                """
            ),
        )

        run_binary("cppref_to_structured", "foo.thrift")

        self.assertEqual(
            read_file("foo.thrift"),
            textwrap.dedent(
                """\
                include "a.thrift"
                include "b.thrift"
                include "c.thrift"
                include "thrift/annotation/cpp.thrift"

                struct Faa {
                    1: i32 faa1;
                    @cpp.Ref{type = cpp.RefType.Unique}
                2: optional Faa faa2 ;
                    3: i32 faa3;
                }
                """
            ),
        )