blob: 4688880fced332a1b8cec1cbf3a5b63929df0c16 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use strict;
use warnings;
use Test::More tests => 101;
use Clownfish::Type;
use Clownfish::Parser;
my $integer_type = Clownfish::Type->new_integer(
specifier => 'int32_t',
const => 1,
);
ok( $integer_type->const, "const" );
is( $integer_type->get_specifier, "int32_t" );
like( $integer_type->to_c, qr/const/, "'const' in C representation" );
my $parser = Clownfish::Parser->new;
my @chy_specifiers = qw(
bool_t
);
my @c_specifiers = qw(
char
short
int
long
size_t
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
);
for my $chy_specifier (@chy_specifiers) {
is( $parser->chy_integer_specifier($chy_specifier),
$chy_specifier, "chy_integer_specifier: $chy_specifier" );
my $type = $parser->chy_integer_type($chy_specifier);
isa_ok( $type, "Clownfish::Type" );
ok( $type && $type->is_integer, "parsed Type is_integer()" );
$type = $parser->chy_integer_type("const $chy_specifier");
isa_ok( $type, "Clownfish::Type" );
ok( $type && $type->is_integer, "parsed const Type is_integer()" );
ok( $type && $type->const, "parsed const Type is const()" );
my $bogus = $chy_specifier . "oot_toot";
ok( !$parser->chy_integer_specifier($bogus),
"chy_integer_specifier guards against partial word matches" );
}
for my $c_specifier (@c_specifiers) {
is( $parser->c_integer_specifier($c_specifier),
$c_specifier, "c_integer_specifier: $c_specifier" );
my $type = $parser->c_integer_type($c_specifier);
isa_ok( $type, "Clownfish::Type" );
ok( $type && $type->is_integer, "parsed Type is_integer()" );
$type = $parser->c_integer_type("const $c_specifier");
isa_ok( $type, "Clownfish::Type" );
ok( $type && $type->is_integer, "parsed const Type is_integer()" );
ok( $type && $type->const, "parsed const Type is const()" );
my $bogus = $c_specifier . "y";
ok( !$parser->c_integer_specifier($bogus),
"c_integer_specifier guards against partial word matches" );
}