<commit_before>use v6;

use Test;
use SemiXML::Sxml;
use XML::XPath;

#-------------------------------------------------------------------------------
subtest 'variables', {

  my $text = q:to/EOTXT/;
    $html [
      #$!SxmlCore.var name=aCommonText [ $strong [Lorem ipsum dolor simet ...] ]
      $sxml:var-decl name=aCommonText [ $strong [Lorem ipsum dolor simet ...] ]
      $body [
        $h1 id=h1001 [ Introduction ]
        $p [ $sxml:var-ref name=aCommonText ]
        $ul [ $li [ $sxml:var-ref name=aCommonText ] ]
      ]
    ]
    EOTXT

  my SemiXML::Sxml $x .= new;
  $x.parse(content => $text);

  # See the result
  my Str $xml-text = ~$x;
  #diag $xml-text;

  my XML::XPath $p .= new(:xml($xml-text));

  is $p.find( '//p/strong/text()', :to-list)[0].text(),
     'Lorem ipsum dolor simet ...',
     'Found 1st substitution';

  is $p.find( '//ul/li/strong/text()', :to-list)[0].text(),
     'Lorem ipsum dolor simet ...',
     'Found 2nd substitution';
}

#-------------------------------------------------------------------------------
subtest 'undeclared variable', {

  my $text = q:to/EOTXT/;
    $html [
      $body [
        $h1 id=h1001 [ Introduction ]
        $p [ $sxml:var-use name=someCommonText ]
      ]
    ]
    EOTXT

  my SemiXML::Sxml $x .= new;
  $x.parse(content => $text);

  # See the result
  my Str $xml-text = ~$x;
  #diag $xml-text;

  my XML::XPath $p .= new(:xml($xml-text));

  is ~$p.find( '//p/sxml:var-use[@name="someCommonText"]', :to-list),
     '', 'undeclared variable sxml:var-use name=someCommonText removed';
}

#-------------------------------------------------------------------------------
done-testing;
<commit_msg>casualties caused by grammar changes<commit_after>use v6;

use Test;
use SemiXML::Sxml;
use XML::XPath;

#-------------------------------------------------------------------------------
subtest 'variables', {

  my $text = q:to/EOTXT/;
    $html [
      #$!SxmlCore.var name=aCommonText [ $strong [Lorem ipsum dolor simet ...] ]
      $sxml:var-decl name=aCommonText [ $strong [Lorem ipsum dolor simet ...] ]
      $body [
        $h1 id=h1001 [ Introduction ]
        $p [ $sxml:var-ref name=aCommonText [] ]
        $ul [ $li [ $sxml:var-ref name=aCommonText [] ] ]
      ]
    ]
    EOTXT

  my SemiXML::Sxml $x .= new;
  $x.parse(content => $text);

  # See the result
  my Str $xml-text = ~$x;
  #diag $xml-text;

  my XML::XPath $p .= new(:xml($xml-text));

  is $p.find( '//p/strong/text()', :to-list)[0].text(),
     'Lorem ipsum dolor simet ...',
     'Found 1st substitution';

  is $p.find( '//ul/li/strong/text()', :to-list)[0].text(),
     'Lorem ipsum dolor simet ...',
     'Found 2nd substitution';
}

#-------------------------------------------------------------------------------
subtest 'undeclared variable', {

  my $text = q:to/EOTXT/;
    $html [
      $body [
        $h1 id=h1001 [ Introduction ]
        $p [ $sxml:var-use name=someCommonText ]
      ]
    ]
    EOTXT

  my SemiXML::Sxml $x .= new;
  $x.parse(content => $text);

  # See the result
  my Str $xml-text = ~$x;
  #diag $xml-text;

  my XML::XPath $p .= new(:xml($xml-text));

  is ~$p.find( '//p/sxml:var-use[@name="someCommonText"]', :to-list),
     '', 'undeclared variable sxml:var-use name=someCommonText removed';
}

#-------------------------------------------------------------------------------
done-testing;

{'fraction_non_alphanumeric': 0.3033343169076424, 'fraction_numerical': 0.00885216878135143, 'mean_word_length': 1.634032634032634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2082999', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1160, 'n_words': 254}