@@ -401,7 +401,7 @@ def get_tree_count(tree, path):
401
401
return len (tree .findall (path ))
402
402
403
403
404
- def check_snapshot (snapshot_name , tree ):
404
+ def check_snapshot (snapshot_name , tree , normalize_to_text ):
405
405
assert rust_test_path .endswith ('.rs' )
406
406
snapshot_path = '{}.{}.{}' .format (rust_test_path [:- 3 ], snapshot_name , 'html' )
407
407
try :
@@ -413,7 +413,10 @@ def check_snapshot(snapshot_name, tree):
413
413
else :
414
414
raise FailedCheck ('No saved snapshot value' )
415
415
416
- actual_str = ET .tostring (tree ).decode ('utf-8' )
416
+ if not normalize_to_text :
417
+ actual_str = ET .tostring (tree ).decode ('utf-8' )
418
+ else :
419
+ actual_str = flatten (tree )
417
420
418
421
if expected_str != actual_str :
419
422
if bless :
@@ -494,11 +497,16 @@ def check_command(c, cache):
494
497
[snapshot_name , html_path , pattern ] = c .args
495
498
tree = cache .get_tree (html_path )
496
499
xpath = normalize_xpath (pattern )
500
+ normalize_to_text = False
501
+ if xpath .endswith ('/text()' ):
502
+ xpath = xpath [:- 7 ]
503
+ normalize_to_text = True
504
+
497
505
subtrees = tree .findall (xpath )
498
506
if len (subtrees ) == 1 :
499
507
[subtree ] = subtrees
500
508
try :
501
- check_snapshot (snapshot_name , subtree )
509
+ check_snapshot (snapshot_name , subtree , normalize_to_text )
502
510
ret = True
503
511
except FailedCheck as err :
504
512
cerr = str (err )
0 commit comments