[erl-frontend] Add tests for nested records

Summary: Add tests for expressions and patterns with nested records.

Reviewed By: rgrig

Differential Revision: D30072210

fbshipit-source-id: e358f2a4a
master
Akos Hajdu 4 years ago committed by Facebook GitHub Bot
parent 078d7c599f
commit f90153b428

@ -75,6 +75,7 @@ codetoanalyze/erlang/features/src/records.erl, test_initializer1_Bad/0, -168, NO
codetoanalyze/erlang/features/src/records.erl, test_initializer2_Bad/0, -180, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here]
codetoanalyze/erlang/features/src/records.erl, test_initializer_explicit_override_Bad/0, -192, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here]
codetoanalyze/erlang/features/src/records.erl, test_initializer_update_override_Bad/0, -205, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here]
codetoanalyze/erlang/features/src/records.erl, test_nested_Bad/0, -231, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here]
codetoanalyze/erlang/features/src/records.erl, test_undefined_Bad/0, -218, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here]
codetoanalyze/erlang/features/src/records.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here]
codetoanalyze/erlang/features/src/short_circuit.erl, accepts_one/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here]

@ -6,6 +6,7 @@
-module(records).
-record(person, {name, phone, address}).
-record(car, {plate, owner}).
-export([
test_index2_Ok/0,
@ -43,7 +44,9 @@
test_initializer_update_override_Ok/0,
test_initializer_update_override_Bad/0,
test_undefined_Ok/0,
test_undefined_Bad/0
test_undefined_Bad/0,
test_nested_Ok/0,
test_nested_Bad/0
]).
% Call this method with warn(1) to trigger a warning to expect
@ -270,3 +273,17 @@ test_undefined_Bad() ->
case P#person.name of
undefined -> warn(1)
end.
test_nested_Ok() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C#car.owner#person.name of
123 -> ok
end.
test_nested_Bad() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C#car.owner#person.name of
123 -> warn(1)
end.

@ -44,6 +44,8 @@ codetoanalyze/erlang/nonmatch/src/records.erl, test_match_field3_Bad/0, 2, NO_MA
codetoanalyze/erlang/nonmatch/src/records.erl, test_match_field4_Bad/0, 2, NO_MATCHING_CASE_CLAUSE, no_bucket, ERROR, [no matching case clause here]
codetoanalyze/erlang/nonmatch/src/records.erl, test_match_field_multiple2_Bad/0, 2, NO_MATCHING_CASE_CLAUSE, no_bucket, ERROR, [no matching case clause here]
codetoanalyze/erlang/nonmatch/src/records.erl, test_match_field_multiple3_Bad/0, 2, NO_MATCHING_CASE_CLAUSE, no_bucket, ERROR, [no matching case clause here]
codetoanalyze/erlang/nonmatch/src/records.erl, test_nested4_Bad/0, 3, NO_MATCHING_CASE_CLAUSE, no_bucket, ERROR, [no matching case clause here]
codetoanalyze/erlang/nonmatch/src/records.erl, test_nested5_Bad/0, 3, NO_MATCHING_CASE_CLAUSE, no_bucket, ERROR, [no matching case clause here]
codetoanalyze/erlang/nonmatch/src/records.erl, test_type_Bad/0, -5, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `accepts_rabbits/1`,no matching function clause here]
codetoanalyze/erlang/nonmatch/src/tuples.erl, accepts_empty/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here]
codetoanalyze/erlang/nonmatch/src/tuples.erl, accepts_tuple_of_two/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here]

@ -7,6 +7,7 @@
-record(person, {name, phone, address}).
-record(rabbit, {name, color}).
-record(car, {plate, owner}).
-export([
test_type_Ok/0,
@ -30,7 +31,12 @@
test_match_as_tuple4_Bad/0,
test_match_as_tuple5_Bad/0,
test_bad_record_access_Bad/0,
test_bad_record_update_Bad/0
test_bad_record_update_Bad/0,
test_nested1_Ok/0,
test_nested2_Ok/0,
test_nested3_Ok/0,
test_nested4_Bad/0,
test_nested5_Bad/0
]).
accepts_rabbits(#rabbit{}) -> ok.
@ -148,3 +154,38 @@ test_bad_record_access_Bad() ->
test_bad_record_update_Bad() ->
P = #person{name = 123, phone = 45, address = 6789},
P#rabbit{name = 9999}.
test_nested1_Ok() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C of
#car{owner = #person{name = 123}} -> ok
end.
test_nested2_Ok() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C of
#car{owner = #person{phone = 45}} -> ok
end.
test_nested3_Ok() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C of
#car{owner = #person{name = 123, address = 6789}} -> ok
end.
test_nested4_Bad() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C of
#car{owner = #person{name = 9999}} -> ok
end.
test_nested5_Bad() ->
P = #person{name = 123, phone = 45, address = 6789},
C = #car{plate = 987654, owner = P},
case C of
#car{owner = #person{name = 123, phone = 99999}} -> ok
end.

Loading…
Cancel
Save