//go:build linux && (amd64 || arm64)
** Copyright (C) 2001-2025 Zabbix SIA
** 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 2 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"golang.zabbix.com/agent2/pkg/zbxregexp"
func TestExecuteRegex(t *testing.T) {
{input: `1`, pattern: `1`, output: ``, result: `1`, match: true},
{input: `1`, pattern: `2`, output: ``, result: `1`, match: false},
{input: `123 456 789"`, pattern: `([0-9]+)`, output: `\1`, result: `123`, match: true},
{input: `value ""`, pattern: `value "([^"]*)"`, output: `\1`, result: ``, match: true},
{input: `b:xyz"`, pattern: `b:([^ ]+)`, output: `\\1`, result: `\1`, match: true},
{input: `a:1 b:2`, pattern: `a:([^ ]+) b:([^ ]+)`, output: `\1,\2`, result: `1,2`, match: true},
{input: `a:\2 b:xyz`, pattern: `a:([^ ]+) b:([^ ]+)`, output: `\1,\2`, result: `\2,xyz`, match: true},
{input: `a value: 10 in text"`, pattern: `value: ([0-9]+)`, output: `\@`, result: `value: 10`,
{input: `a value: 10 in text"`, pattern: `value: ([0-9]+)`, output: `\0`, result: `value: 10`,
{input: `a:9 b:2`, pattern: `a:([^\d ]+) | b:([^ ]+)`, output: `\0,\1,\2`, result: ` b:2,,2`,
for _, c := range tests {
t.Run(c.input, func(t *testing.T) {
rx, _ := regexp.Compile(c.pattern)
r, m := zbxregexp.ExecuteRegex([]byte(c.input), rx, []byte(c.output))
t.Errorf("expected match while returned false")