package lux;

import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class SearchTestNS extends BaseSearchTest {
    
    @BeforeClass
    public static void setup() throws Exception {
        setup ("lux/reader-test-ns.xml", "lux/reader-test.xml");
    }
    
    @Test
    public void testSearchNS () throws Exception {
        // namespace prefix may be supplied explicitly
        assertSearch ("2", "count(lux:search('<x\\:title:test'))", null, 2);
        // no namespace
        assertSearch ("2", "count(lux:search('<title:test'))", null, 2);
    }

    @Test
    public void testSearchNsUri () throws Exception {
        // namespace may be supplied explicitly
        assertSearch ("2", "count(lux:search('<title\\{http\\://lux.net\\{test\\}\\}:test'))", null, 2);
    }
    
    @Test @Ignore
    public void testSearchBoundNsPrefix() throws Exception {
        // Ideally, search string could use prefixes declared in surrounding context
        // This test should be run with a namespace-aware idnex
        assertSearch ("2", "declare namespace x='http://lux.net{test}'; count(lux:search('<x\\:title:test'))", null, 2);
    }
    
    @Test
    public void testSearchWildcardNamespace () throws Exception {
        // wildcarded namespace
        assertSearch ("4", "count(lux:search('<*:test'))", null, 4);
    }

}

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

@@ -1352,16 +1352,1040 @@
 );%0A    %7D
+%0A    %0A    @Test%0A    public void testGeneratePathQuery () throws Exception %7B%0A        // generates a query that matches a document that doesn't actually satisfy the query%0A        assertSearch (%222%22, %22count(/entities)%22, null, 4);%0A        assertSearch (%220%22, %22declare namespace x='x'; count(/x:title)%22, null, 0);%0A        // this actually has the correct namespace%0A        /* FIXME:%0A         * namespace-unaware is not actually that helpful: it will lead to over-matching%0A         * To correctly match generated queries, which must be namespace-aware to maintain correct%0A         * behavior, it would be necessary to index both the reverse-clark name *and* the prefixed%0A         * lexical QName.%0A         * We could get most of the benefit of the namespace-unawareness by supporting%0A         * wildcarded namespace index queries%0A         */%0A        assertSearch (%221%22, %22declare namespace x='http://lux.net%7Btest%7D'; count(/x:title)%22, null, 1);%0A        assertSearch (%221%22, %22declare namespace x='#2'; count(/x:entities)%22, null, 1);%0A    %7D
 %0A%0A%7D%0A%0A/* 

test for namespace queries