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
|
# TestSwiftOptionals.py
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ------------------------------------------------------------------------------
"""
Check formatting for T? and T!
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import os
import unittest2
class TestSwiftOptionalType(TestBase):
@swiftTest
def test_swift_optional_type(self):
"""Check formatting for T? and T!"""
self.do_check_consistency()
self.do_check_visuals()
self.do_check_api()
def do_check_consistency(self):
"""Check formatting for T? and T!"""
self.build()
lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))
def do_check_visuals(self):
"""Check formatting for T? and T!"""
self.expect(
"frame variable optS_Some",
substrs=[
'a = 12',
'b = "Hello world"'])
self.expect(
"frame variable uoptS_Some",
substrs=[
'a = 12',
'b = "Hello world"'])
self.expect("frame variable optString_Some", substrs=['"hello"'])
self.expect("frame variable uoptString_Some", substrs=['"hello"'])
self.expect("frame variable optS_None", substrs=['nil'])
self.expect("frame variable uoptS_None", substrs=['nil'])
self.expect("frame variable optString_None", substrs=['nil'])
self.expect("frame variable uoptString_None", substrs=['nil'])
self.expect("frame variable optTrue", substrs=['Bool?', 'true'])
self.expect("frame variable optFalse", substrs=['Bool?','false'])
self.expect("frame variable optNil", substrs=['Bool?', 'nil'])
def do_check_api(self):
"""Check formatting for T? and T!"""
optS_Some = self.frame().FindVariable("optS_Some")
lldbutil.check_variable(
self,
optS_Some,
use_dynamic=False,
num_children=2)
uoptS_Some = self.frame().FindVariable("uoptS_Some")
lldbutil.check_variable(
self,
uoptS_Some,
use_dynamic=False,
num_children=2)
optString_None = self.frame().FindVariable("optString_None")
lldbutil.check_variable(
self,
optString_None,
use_dynamic=False,
num_children=0)
uoptString_None = self.frame().FindVariable("uoptString_None")
lldbutil.check_variable(
self,
uoptString_None,
use_dynamic=False,
num_children=0)
optString_Some = self.frame().FindVariable("optString_Some")
lldbutil.check_variable(
self,
optString_Some,
use_dynamic=False,
num_children=1)
uoptString_Some = self.frame().FindVariable("uoptString_Some")
lldbutil.check_variable(
self,
uoptString_Some,
use_dynamic=False,
num_children=1)
uoptString_Some.GetChildAtIndex(99)
optTrue = self.frame().FindVariable("optTrue")
lldbutil.check_variable(
self,
optTrue,
use_dynamic=False,
num_children=1,
summary='true')
optFalse = self.frame().FindVariable("optFalse")
lldbutil.check_variable(
self,
optFalse,
use_dynamic=False,
num_children=1,
summary='false')
optNil = self.frame().FindVariable("optNil")
lldbutil.check_variable(
self,
optNil,
use_dynamic=False,
num_children=0,
summary='nil')
# Querying a non-existing child should not crash.
synth_valobj = self.frame().FindVariable("optString_Some")
synth_valobj.SetSyntheticChildrenGenerated(True);
self.assertEqual(synth_valobj.GetChildAtIndex(1).GetSummary(), None)
|