RegressionTests__XPathTests.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Feb 2020 17:18:51 +0100
changeset 2579 bec2c103be07
parent 2485 20030382232b
permissions -rw-r--r--
#OTHER by cg s

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 2018 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:goodies/regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#XPathTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression-XML'
!

!XPathTests class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2018 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    documentation to be added.

    [author:]
        Claus Gittinger

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!XPathTests class methodsFor:'queries'!

requiredPackageNames
    ^ #('stx:goodies/xml/xpath')

    "Created: / 29-05-2019 / 01:36:02 / Claus Gittinger"
! !

!XPathTests methodsFor:'tests'!

test01
    |node child|

    "/                              123456789012
    node := XML::XPathParser parse:'/foo/bar/baz'.
    self assert:(node condensedPrintString = '/foo/bar/baz').

    self assert:(node startPosition == 1).
    self assert:(node endPosition == 1).
    self assert:(node isXPathRoot).

    child := node child.
    self assert:(child startPosition == 2).
    "/ self assert:(child endPosition == 4).

    child := child child.
    self assert:(child startPosition == 6).
    "/ self assert:(child endPosition == 8).

    child := child child.
    self assert:(child startPosition == 10).
    "/ self assert:(child endPosition == 12).

    "/                              123456789012
    node := XML::XPathParser parse:'/foo/../baz'.
    self assert:(node condensedPrintString = '/foo/../baz').

    self assert:(node startPosition == 1).
    self assert:(node endPosition == 1).
    self assert:(node isXPathRoot).

    child := node child.
    self assert:(child startPosition == 2).
    "/ self assert:(child endPosition == 4).

    child := child child.
    self assert:(child startPosition == 6).
    "/ self assert:(child endPosition == 7).

    child := child child.
    self assert:(child startPosition == 9).
    "/ self assert:(child endPosition == 11).

    "/                              123456789012
    node := XML::XPathParser parse:'/foo[1]/baz'.
    self assert:(node condensedPrintString = '/foo[1]/baz').

    self assert:(node startPosition == 1).
    self assert:(node endPosition == 1).
    self assert:(node isXPathRoot).

    child := node child.
    self assert:(child startPosition == 2).
    "/ self assert:(child endPosition == 4).

    child := child child.
    self assert:(child startPosition == 9).
    "/ self assert:(child endPosition == 11).

    "/                              1234567890123456789
    node := XML::XPathParser parse:'/foo[@name="bla"]/baz'.
    self assert:(node condensedPrintString = '/foo[@name = "bla"]/baz').

    self assert:(node startPosition == 1).
    self assert:(node endPosition == 1).
    self assert:(node isXPathRoot).

    child := node child.
    self assert:(child startPosition == 2).
    "/ self assert:(child endPosition == 4).

    child := child child.
    self assert:(child startPosition == 19).
    "/ self assert:(child endPosition == 11).

    "
     self run:#test01
     self new test01
    "

    "Created: / 24-09-2018 / 20:17:35 / Claus Gittinger"
!

test02
    |node child dom nodeContext matchingDomNode|

    "/                                       1         2         3   
    "/                              1234567890123456789012345678901234567890
    node := XML::XPathParser parse:'/child::foo/child::bar/child::baz'.
    self assert:(node condensedPrintString = '/foo/bar/baz').
    self assert:(node printString = '/child::foo/child::bar/child::baz').

    self assert:(node startPosition == 1).
    self assert:(node endPosition == 1).
    self assert:(node isXPathRoot).

    child := node child.
    self assert:(child startPosition == 2).
    "/ self assert:(child endPosition == 4).

    child := child child.
    self assert:(child startPosition == 13).
    "/ self assert:(child endPosition == 8).

    child := child child.
    self assert:(child startPosition == 24).
    "/ self assert:(child endPosition == 12).

    dom := XML::XMLParser parse:'
<foo>
  <bar>
    <baz>
      text
    </baz>
  </bar>
</foo>
'.

    nodeContext := node xpathValueFor:dom variables:#().
    self assert:(nodeContext unsortedNodes size == 1).
    matchingDomNode := nodeContext unsortedNodes first.
    self assert:(matchingDomNode tag type = 'baz').

    dom := XML::XMLParser parse:'
<foo>
  <bar>
    <baz>
      text1
    </baz>
    <baz>
      text2
    </baz>
  </bar>
</foo>
'.

    nodeContext := node xpathValueFor:dom variables:#().
    self assert:(nodeContext unsortedNodes size == 2).

    "
     self run:#test02
     self new test02
    "

    "Created: / 25-09-2018 / 23:47:18 / Claus Gittinger"
! !

!XPathTests class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
! !