go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/core/resources/regex_test.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package resources_test 5 6 import ( 7 "testing" 8 9 "go.mondoo.com/cnquery/providers-sdk/v1/testutils" 10 ) 11 12 var emojiTestString = []rune("โโบโฟ๐๐๐๐๐๐๐ต๐ผ๐ค๐คฃ๐ฅณ๐งก๐งฟ๐ฉฐ๐ซ") 13 14 func TestRegex_Methods(t *testing.T) { 15 x.TestSimple(t, []testutils.SimpleTest{ 16 { 17 Code: "'hello bob'.find(/he\\w*\\s?[bo]+/)", 18 ResultIndex: 0, 19 Expectation: []interface{}{"hello bob"}, 20 }, 21 { 22 Code: "'HellO'.find(/hello/i)", 23 ResultIndex: 0, 24 Expectation: []interface{}{"HellO"}, 25 }, 26 { 27 Code: "'hello\nworld'.find(/hello.world/s)", 28 ResultIndex: 0, 29 Expectation: []interface{}{"hello\nworld"}, 30 }, 31 { 32 Code: "'yo! hello\nto the world'.find(/\\w+$/m)", 33 ResultIndex: 0, 34 Expectation: []interface{}{"hello", "world"}, 35 }, 36 { 37 Code: "'IPv4: 0.0.0.0, 255.255.255.255, 1.50.120.230, 256.0.0.0 '.find(regex.ipv4)", 38 ResultIndex: 0, 39 Expectation: []interface{}{"0.0.0.0", "255.255.255.255", "1.50.120.230"}, 40 }, 41 { 42 Code: "'IPv6: 2001:0db8:85a3:0000:0000:8a2e:0370:7334'.find(regex.ipv6)", 43 ResultIndex: 0, 44 Expectation: []interface{}{"2001:0db8:85a3:0000:0000:8a2e:0370:7334"}, 45 }, 46 { 47 Code: "'Sarah Summers <sarah@summe.rs>'.find( regex.email )", 48 ResultIndex: 0, 49 Expectation: []interface{}{"sarah@summe.rs"}, 50 }, 51 { 52 Code: "'one+1@sum.me.rs:'.find( regex.email )", 53 ResultIndex: 0, 54 Expectation: []interface{}{"one+1@sum.me.rs"}, 55 }, 56 { 57 Code: "'Urls: http://mondoo.com/welcome'.find( regex.url )", 58 ResultIndex: 0, 59 Expectation: []interface{}{"http://mondoo.com/welcome"}, 60 }, 61 { 62 Code: "'mac 01:23:45:67:89:ab attack'.find(regex.mac)", 63 ResultIndex: 0, 64 Expectation: []interface{}{"01:23:45:67:89:ab"}, 65 }, 66 { 67 Code: "'uuid: b7f99555-5bca-48f4-b86f-a953a4883383.'.find(regex.uuid)", 68 ResultIndex: 0, 69 Expectation: []interface{}{"b7f99555-5bca-48f4-b86f-a953a4883383"}, 70 }, 71 { 72 Code: "'some โฎ" + string(emojiTestString) + " โฎ emojis'.find(regex.emoji).length", 73 ResultIndex: 0, Expectation: int64(len(emojiTestString)), 74 }, 75 { 76 Code: "'semvers: 1, 1.2, 1.2.3, 1.2.3-4'.find(regex.semver)", 77 ResultIndex: 0, 78 Expectation: []interface{}{"1.2.3", "1.2.3-4"}, 79 }, 80 }) 81 }