1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
use lib 't/lib';
use GQLTest;
use GraphQL::Language::Parser qw(parse);
blockstring_test([
'',
' Hello,',
' World!',
'',
' Yours,',
' GraphQL.',
], ['Hello,', ' World!', '', 'Yours,', ' GraphQL.'], 'removes uniform indentation from a string');
blockstring_test([
'',
'',
' Hello,',
' World!',
'',
' Yours,',
' GraphQL.',
'',
'',
], ['Hello,', ' World!', '', 'Yours,', ' GraphQL.'], 'removes empty leading and trailing lines');
blockstring_test([
' ',
' ',
' Hello,',
' World!',
'',
' Yours,',
' GraphQL.',
' ',
' ',
], ['Hello,', ' World!', '', 'Yours,', ' GraphQL.'], 'removes blank leading and trailing lines');
blockstring_test([
' Hello,',
' World!',
'',
' Yours,',
' GraphQL.',
], [' Hello,', ' World!', '', 'Yours,', ' GraphQL.'], 'retains indentation from first line');
blockstring_test([
' ',
' Hello, ',
' World! ',
' ',
' Yours, ',
' GraphQL. ',
' ',
], [
'Hello, ',
' World! ',
' ',
'Yours, ',
' GraphQL. ',
], 'does not alter trailing spaces');
done_testing;
sub blockstring_test {
my ($raw, $expect, $msg) = @_;
my $got = parse(string_make(join("\n", @$raw)));
is string_lookup($got), join("\n", @$expect), $msg or diag explain $got;
}
sub string_make {
my ($text) = @_;
return query_make(sprintf '"""%s"""', $text);
}
sub query_make {
my ($text) = @_;
return sprintf 'query q { foo(name: %s) { id } }', $text;
}
sub string_lookup {
my ($got) = @_;
return query_lookup($got, 'string');
}
sub query_lookup {
my ($got, $type) = @_;
return $got->[0]{selections}[0]{arguments}{name};
}
|