| 1 | # $Id: substr 2413 2010-09-11 17:43:04Z bird $ -*-perl-*-
|
|---|
| 2 | ## @file
|
|---|
| 3 | # $(substr str, start[, length[, pad]])
|
|---|
| 4 | #
|
|---|
| 5 |
|
|---|
| 6 | #
|
|---|
| 7 | # Copyright (c) 2008-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
|---|
| 8 | #
|
|---|
| 9 | # This file is part of kBuild.
|
|---|
| 10 | #
|
|---|
| 11 | # kBuild is free software; you can redistribute it and/or modify
|
|---|
| 12 | # it under the terms of the GNU General Public License as published by
|
|---|
| 13 | # the Free Software Foundation; either version 3 of the License, or
|
|---|
| 14 | # (at your option) any later version.
|
|---|
| 15 | #
|
|---|
| 16 | # kBuild is distributed in the hope that it will be useful,
|
|---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | # GNU General Public License for more details.
|
|---|
| 20 | #
|
|---|
| 21 | # You should have received a copy of the GNU General Public License
|
|---|
| 22 | # along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 |
|
|---|
| 26 | $description = "Tests the $(substr ) function";
|
|---|
| 27 |
|
|---|
| 28 | $details = "A few simple tests and edge cases.";
|
|---|
| 29 |
|
|---|
| 30 | if ($is_kmk) {
|
|---|
| 31 |
|
|---|
| 32 | # TEST #0 - check that the feature is present.
|
|---|
| 33 | # --------------------------------------------
|
|---|
| 34 | run_make_test('
|
|---|
| 35 | ifneq ($(substr asdf,4),f)
|
|---|
| 36 | $(error sub-test 0 failed)
|
|---|
| 37 | endif
|
|---|
| 38 | .PHONY: all
|
|---|
| 39 | all: ; @:
|
|---|
| 40 | ',
|
|---|
| 41 | '',
|
|---|
| 42 | '');
|
|---|
| 43 |
|
|---|
| 44 | # TEST #1 - the real test.
|
|---|
| 45 | # ------------------------
|
|---|
| 46 | run_make_test('
|
|---|
| 47 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20),tuvwxyz)
|
|---|
| 48 | $(error sub-test 0 failed)
|
|---|
| 49 | endif
|
|---|
| 50 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20,1),t)
|
|---|
| 51 | $(error sub-test 1 failed)
|
|---|
| 52 | endif
|
|---|
| 53 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20,2),tu)
|
|---|
| 54 | $(error sub-test 2 failed)
|
|---|
| 55 | endif
|
|---|
| 56 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,20,0),)
|
|---|
| 57 | $(error sub-test 3 failed)
|
|---|
| 58 | endif
|
|---|
| 59 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-1),z)
|
|---|
| 60 | $(error sub-test 4 failed)
|
|---|
| 61 | endif
|
|---|
| 62 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2),yz)
|
|---|
| 63 | $(error sub-test 5 failed)
|
|---|
| 64 | endif
|
|---|
| 65 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2,2),yz)
|
|---|
| 66 | $(error sub-test 6 failed)
|
|---|
| 67 | endif
|
|---|
| 68 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2,3),yz)
|
|---|
| 69 | $(error sub-test 7 failed)
|
|---|
| 70 | endif
|
|---|
| 71 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-2,5,XYZ),yzXYZ)
|
|---|
| 72 | $(error sub-test 8 failed)
|
|---|
| 73 | endif
|
|---|
| 74 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-25,1),b)
|
|---|
| 75 | $(error sub-test 9 failed)
|
|---|
| 76 | endif
|
|---|
| 77 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-26,1),a)
|
|---|
| 78 | $(error sub-test 10 failed)
|
|---|
| 79 | endif
|
|---|
| 80 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,1),)
|
|---|
| 81 | $(error sub-test 11 failed)
|
|---|
| 82 | endif
|
|---|
| 83 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,2),a)
|
|---|
| 84 | $(error sub-test 12 failed)
|
|---|
| 85 | endif
|
|---|
| 86 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,3),ab)
|
|---|
| 87 | $(error sub-test 13 failed)
|
|---|
| 88 | endif
|
|---|
| 89 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-27,3,_),_ab)
|
|---|
| 90 | $(error sub-test 14 failed)
|
|---|
| 91 | endif
|
|---|
| 92 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-28,4,.^),.^ab)
|
|---|
| 93 | $(error sub-test 15 failed)
|
|---|
| 94 | endif
|
|---|
| 95 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-50,4),)
|
|---|
| 96 | $(error sub-test 16 failed)
|
|---|
| 97 | endif
|
|---|
| 98 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,-50,4,.^),.^.^)
|
|---|
| 99 | $(error sub-test 17 failed)
|
|---|
| 100 | endif
|
|---|
| 101 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,27,4,.^),.^.^)
|
|---|
| 102 | $(error sub-test 18 failed)
|
|---|
| 103 | endif
|
|---|
| 104 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,28,3,.^),.^.)
|
|---|
| 105 | $(error sub-test 19 failed)
|
|---|
| 106 | endif
|
|---|
| 107 | SP := $(subst ., ,.)
|
|---|
| 108 | ifneq (.$(substr abcdefghijklmnopqrstuvwxyz,100,3, ).,. .)
|
|---|
| 109 | $(error sub-test 20 failed)
|
|---|
| 110 | endif
|
|---|
| 111 | ifneq ($(substr abcdefghijklmnopqrstuvwxyz,100,3, ),$(SP)$(SP)$(SP))
|
|---|
| 112 | $(error sub-test 21 failed)
|
|---|
| 113 | endif
|
|---|
| 114 |
|
|---|
| 115 | .PHONY: all
|
|---|
| 116 | all: ; @:
|
|---|
| 117 | ',
|
|---|
| 118 | '',
|
|---|
| 119 | '');
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | # Indicate that we're done.
|
|---|
| 124 | 1;
|
|---|
| 125 |
|
|---|