<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2011, <NAME>
%%% @doc
%%%
%%% @end
%%% Created :  5 Feb 2011 by <NAME> <<EMAIL>>
%%%-------------------------------------------------------------------
-module(protobuffs_parser_tests).

-include_lib("eunit/include/eunit.hrl").

package_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("package \"test.package\";"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{package,"test.package"}]},Parsed)].

import_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("import \"test.package\";"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{import,"test.package"}]},Parsed)].

message_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Test { required string name = 1; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Test",[{1,required,"string","name",none}]}]},Parsed)].

message_default_test_() ->
	{ok,Result,1} = protobuffs_scanner:string("message Test { optional float value = 1 [default=0.01]; optional string stringvalue = 2 [default=\"\"];}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Test",[{1,optional,"float","value",0.01},{2,optional,"string","stringvalue",""}]}]},Parsed)].

packed_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Test { repeated float values = 1 [packed=true]; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Test",[{1,repeated_packed,"float","values",none}]}]},Parsed)].

enum_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("enum MyEnum { VALUE0 = 0; VALUE1 = 1;}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{enum, "MyEnum", [{'VALUE0',0},{'VALUE1',1}]}]},Parsed)].

enum_negative_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("enum MyEnum { VALUE0 = 0; VALUE1 = -1; VALUE2 = 2147483648; VALUE3 = -2147483647;}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{enum, "MyEnum", [{'VALUE0',0},{'VALUE1',-1},{'VALUE2',2147483648},{'VALUE3',-2147483647}]}]},Parsed)].

service_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("service SearchService { rpc Search (SearchRequest) returns (SearchResponse);}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{service, "SearchService", [{rpc, "Search", "SearchRequest", "SearchResponse"}]}]},Parsed)].

extensions_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Foo { extensions 100 to 199; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Foo", [{extensions, 100, 199}]}]},Parsed)].

extend_test_() ->
    {ok, Result, 1} = protobuffs_scanner:string("extend Foo { optional int32 bar = 126; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{extend, "Foo", [{126, optional, "int32", "bar", none}]}]}, Parsed)].

option_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("option message_set_wire_format = true;"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{option,message_set_wire_format,true}]}, Parsed)].

inner_option_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Foo { option message_set_wire_format = true;}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Foo", [{option,message_set_wire_format,true}]}]}, Parsed)].
<commit_msg>Added basic eunit test for nested messages.<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2011, <NAME>
%%% @doc
%%%
%%% @end
%%% Created :  5 Feb 2011 by <NAME> <<EMAIL>>
%%%-------------------------------------------------------------------
-module(protobuffs_parser_tests).

-include_lib("eunit/include/eunit.hrl").

package_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("package \"test.package\";"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{package,"test.package"}]},Parsed)].

import_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("import \"test.package\";"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{import,"test.package"}]},Parsed)].

message_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Test { required string name = 1; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Test",[{1,required,"string","name",none}]}]},Parsed)].

message_default_test_() ->
	{ok,Result,1} = protobuffs_scanner:string("message Test { optional float value = 1 [default=0.01]; optional string stringvalue = 2 [default=\"\"];}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Test",[{1,optional,"float","value",0.01},{2,optional,"string","stringvalue",""}]}]},Parsed)].

packed_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Test { repeated float values = 1 [packed=true]; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Test",[{1,repeated_packed,"float","values",none}]}]},Parsed)].

enum_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("enum MyEnum { VALUE0 = 0; VALUE1 = 1;}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{enum, "MyEnum", [{'VALUE0',0},{'VALUE1',1}]}]},Parsed)].

enum_negative_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("enum MyEnum { VALUE0 = 0; VALUE1 = -1; VALUE2 = 2147483648; VALUE3 = -2147483647;}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{enum, "MyEnum", [{'VALUE0',0},{'VALUE1',-1},{'VALUE2',2147483648},{'VALUE3',-2147483647}]}]},Parsed)].

service_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("service SearchService { rpc Search (SearchRequest) returns (SearchResponse);}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{service, "SearchService", [{rpc, "Search", "SearchRequest", "SearchResponse"}]}]},Parsed)].

extensions_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Foo { extensions 100 to 199; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Foo", [{extensions, 100, 199}]}]},Parsed)].

extend_test_() ->
    {ok, Result, 1} = protobuffs_scanner:string("extend Foo { optional int32 bar = 126; }"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{extend, "Foo", [{126, optional, "int32", "bar", none}]}]}, Parsed)].

option_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("option message_set_wire_format = true;"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{option,message_set_wire_format,true}]}, Parsed)].

inner_option_test_() ->
    {ok,Result,1} = protobuffs_scanner:string("message Foo { option message_set_wire_format = true;}"),
    Parsed = protobuffs_parser:parse(Result),
    [?_assertMatch({ok,[{message, "Foo", [{option,message_set_wire_format,true}]}]}, Parsed)].

nested_message_test_() ->
	{ok,Result,1} = protobuffs_scanner:string("message Test { required Nested nested = 1; message Nested { } }"),
    Parsed = protobuffs_parser:parse(Result),
	[?_assertMatch({ok,[{message, "Test",[{1, required, "Nested", "nested", none}, {message, "Nested", []}]}]},Parsed)].
{'fraction_non_alphanumeric': 0.2410750644767205, 'fraction_numerical': 0.03217049002307588, 'mean_word_length': 5.054231717337716, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1763535', 'n_tokens_mistral': 2716, 'n_tokens_neox': 2508, 'n_words': 387}