From b84dc2f2a681aec8fca974573118a2b470083179 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 27 Feb 2020 21:43:40 -0800 Subject: [PATCH] Add integration test for regex_search filter. --- .../targets/filter_core/tasks/main.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/integration/targets/filter_core/tasks/main.yml b/test/integration/targets/filter_core/tasks/main.yml index 9db278dde80..230b7b4f62d 100644 --- a/test/integration/targets/filter_core/tasks/main.yml +++ b/test/integration/targets/filter_core/tasks/main.yml @@ -235,3 +235,29 @@ - assert: that: - "result.msg.startswith('The task includes an option with an undefined variable')" + +- name: regex_search + set_fact: + match_case: "{{ 'hello' | regex_search('HELLO', ignorecase=false) }}" + ignore_case: "{{ 'hello' | regex_search('HELLO', ignorecase=true) }}" + single_line: "{{ 'hello\nworld' | regex_search('^world', multiline=false) }}" + multi_line: "{{ 'hello\nworld' | regex_search('^world', multiline=true) }}" + named_groups: "{{ 'goodbye' | regex_search('(?Pgood)(?Pbye)', '\\g', '\\g') }}" + numbered_groups: "{{ 'goodbye' | regex_search('(good)(bye)', '\\2', '\\1') }}" + +- name: regex_search unknown argument (failure expected) + set_fact: + unknown_arg: "{{ 'hello' | regex_search('hello', 'unknown') }}" + ignore_errors: yes + register: failure + +- name: regex_search check + assert: + that: + - match_case == '' + - ignore_case == 'hello' + - single_line == '' + - multi_line == 'world' + - named_groups == ['bye', 'good'] + - numbered_groups == ['bye', 'good'] + - failure is failed