aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dlang/expression.exp
blob: d8dc3d1dad720a610f35eb6962183903ae329243 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright (C) 2014-2020 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Test basic builtin types.
# NOTE: The tests here intentionally do not require a D compiler.

load_lib "d-support.exp"

if { [skip_d_tests] } { continue }

proc test_d_integer_literals {} {
    # Test valid D integer literals are accepted.

    gdb_test "print 123456" " = 123456"
    gdb_test "print 123_456" " = 123456"
    gdb_test "print 1_2_3_4_5_6_" " = 123456"

    gdb_test "print 0x123456" " = 1193046"
    gdb_test "print 0x123_456" " = 1193046"
    gdb_test "print 0x1_2_3_4_5_6_" " = 1193046"

    gdb_test "print 0123456" " = 42798"
    gdb_test "print 0123_456" " = 42798"
    gdb_test "print 01_2_3_4_5_6_" " = 42798"

    gdb_test "print 0b101010" " = 42"
    gdb_test "print 0b101_010" " = 42"
    gdb_test "print 0b1_0_1_0_1_0_" " = 42"

    # Usual decimal notation
    gdb_test "ptype 0" "type = int"
    gdb_test "ptype 2_147_483_647" "type = int"
    gdb_test "ptype 2_147_483_648" "type = long"
    gdb_test "ptype 4_294_967_296" "type = long"

    # Explicit suffixes
    gdb_test "ptype 0L" "type = long"
    gdb_test "ptype 2_147_483_648U" "type = uint"
    gdb_test "ptype 4_294_967_296U" "type = ulong"
    gdb_test "ptype 0UL" "type = ulong"
    gdb_test "ptype 0LU" "type = ulong"

    # Hexadecimal notation
    gdb_test "ptype 0x0" "type = int"
    gdb_test "ptype 0x7FFF_FFFF" "type = int"
    gdb_test "ptype 0x8000_0000" "type = uint"
    gdb_test "ptype 0x1_0000_0000" "type = long"

    # Hexadecimal notation with explicit suffixes
    gdb_test "ptype 0x0L" "type = long"
    gdb_test "ptype 0x7FFF_FFFFU" "type = uint"
    gdb_test "ptype 0x1_0000_0000U" "type = ulong"
    gdb_test "ptype 0x0UL" "type = ulong"
    gdb_test "ptype 0x0LU" "type = ulong"

    # Octal notation
    gdb_test "ptype 00" "type = int"
    gdb_test "ptype 017_777_777_777" "type = int"
    gdb_test "ptype 020_000_000_000" "type = uint"
    gdb_test "ptype 040_000_000_000" "type = long"

    # Octal notation with explicit suffixes
    gdb_test "ptype 00L" "type = long"
    gdb_test "ptype 017_777_777_777U" "type = uint"
    gdb_test "ptype 040_000_000_000U" "type = ulong"
    gdb_test "ptype 00UL" "type = ulong"
    gdb_test "ptype 00LU" "type = ulong"

    # Binary notation
    gdb_test "ptype 0b0" "type = int"
    gdb_test "ptype 0b1111111111111111111111111111111" "type = int"
    gdb_test "ptype 0b10000000000000000000000000000000" "type = uint"
    gdb_test "ptype 0b100000000000000000000000000000000" "type = long"

    # Binary notation with explicit suffixes
    gdb_test "ptype 0b0L" "type = long"
    gdb_test "ptype 0b1111111111111111111111111111111U" "type = uint"
    gdb_test "ptype 0b100000000000000000000000000000000U" "type = ulong"
    gdb_test "ptype 0b0UL" "type = ulong"
    gdb_test "ptype 0b0LU" "type = ulong"
}

proc test_d_float_literals {} {
    # Test valid D float literals are accepted.

    gdb_test "ptype 123_456.567_8" "type = double"
    gdb_test "ptype 1_2_3_4_5_6_._5_6_7_8" "type = double"
    gdb_test "ptype 1_2_3_4_5_6_._5e-6_" "type = double"
    gdb_test "ptype 0x1.FFFFFFFFFFFFFp1023" "type = double"
    gdb_test "ptype 0x1p-52L" "type = real"
    gdb_test "ptype 1.175494351e-38F" "type = float"
    gdb_test "ptype 6.3i" "type = idouble"
    gdb_test "ptype 6.3fi" "type = ifloat"
    gdb_test "ptype 6.4Li" "type = ireal"
}

proc test_d_expressions {} {
    # Test expression behaviour specific to D.

    # Comparison and order expressions have same precedence.
    gdb_test "print 1 == 2 > 0" "A syntax error in expression, near `> 0'\."
    gdb_test "print (1 == 2) > 0" " = false"

    # Exponent expressions
    gdb_test "print 5 ^^ 5" "3125"
    gdb_test "print 144 ^^ 0.5" "12"
    gdb_test "print (-10 ^^ 2)" "-100"
    gdb_test "print (-10) ^^ 2" "100"

    gdb_test_no_output "set \$var = 144 ^^ 0.5" ""
    gdb_test "print \$var ^^= 2" "144"
}

# Start with a fresh gdb.

gdb_exit
gdb_start

if [set_lang_d] {
    test_d_integer_literals
    test_d_float_literals
    test_d_expressions
} else {
    warning "D type tests suppressed."
}