/*
 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.data.api.schema.stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.util.Set;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;

public class YT1433Test {
    private static EffectiveModelContext CONTEXT;

    @BeforeAll
    public static void beforeAll() {
        CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/YT1433");
    }

    @Test
    public void testContainerAugmentContainer() throws IOException {
        final FormattingNormalizedNodeStreamWriter streamWriter = new FormattingNormalizedNodeStreamWriter();

        final QName bar = QName.create("foo", "bar");
        final QName baz = QName.create("foo", "baz");

        final YangInstanceIdentifier path = YangInstanceIdentifier.builder()
            .node(QName.create("foo", "foo"))
            .node(AugmentationIdentifier.create(Set.of(bar)))
            .node(bar)
            .node(AugmentationIdentifier.create(Set.of(baz)))
            .node(baz)
            .build();

        try (var iidWriter = YangInstanceIdentifierWriter.open(streamWriter, CONTEXT, path)) {
            try (var nnWriter = new NormalizedNodeWriter(streamWriter)) {
                // No-op
            }
        }

        assertEquals("(foo)foo(container)\n"
            + "  AugmentationIdentifier{childNames=[(foo)bar]}(augmentation)\n"
            + "    (foo)bar(container)\n"
            + "      AugmentationIdentifier{childNames=[(foo)baz]}(augmentation)\n"
            + "        (foo)baz(container)\n"
            + "        (end)\n"
            + "      (end)\n"
            + "    (end)\n"
            + "  (end)\n"
            + "(end)\n", streamWriter.result());
    }

    @Test
    public void testChoiceAugmentCointainer() throws IOException {
        final FormattingNormalizedNodeStreamWriter streamWriter = new FormattingNormalizedNodeStreamWriter();

        final QName bar = QName.create("bar", "bar");
        final QName baz = QName.create("bar", "baz");

        final YangInstanceIdentifier path = YangInstanceIdentifier.builder()
            .node(QName.create("bar", "foo"))
            .node(bar)
            .node(baz)
            .build();

        try (var iidWriter = YangInstanceIdentifierWriter.open(streamWriter, CONTEXT, path)) {
            try (var nnWriter = new NormalizedNodeWriter(streamWriter)) {
                // No-op
            }
        }

        assertEquals("(bar)foo(choice)\n"
            + "  (bar)bar(container)\n"
            + "    (bar)baz(container)\n"
            + "    (end)\n"
            + "  (end)\n"
            + "(end)\n", streamWriter.result());
    }
}

@@ -1987,16 +1987,31 @@
 Equals(%22
+%22%22%0A            
 (foo)foo
@@ -2013,35 +2013,32 @@
 o)foo(container)
-%5Cn%22
 %0A            + %22
@@ -2034,19 +2034,16 @@
         
-+ %22
   Augmen
@@ -2087,35 +2087,32 @@
 %5D%7D(augmentation)
-%5Cn%22
 %0A            + %22
@@ -2104,27 +2104,24 @@
             
-+ %22
     (foo)bar
@@ -2123,35 +2123,32 @@
 o)bar(container)
-%5Cn%22
 %0A            + %22
@@ -2140,27 +2140,24 @@
             
-+ %22
       Augmen
@@ -2209,19 +2209,16 @@
 ntation)
-%5Cn%22
 %0A       
@@ -2222,27 +2222,24 @@
         
-+ %22
+ 
        
- 
 (foo)baz
@@ -2241,35 +2241,32 @@
 o)baz(container)
-%5Cn%22
 %0A            + %22
@@ -2258,27 +2258,24 @@
             
-+ %22
         (end
@@ -2267,35 +2267,32 @@
            (end)
-%5Cn%22
 %0A            + %22
@@ -2284,27 +2284,24 @@
             
-+ %22
       (end)%5C
@@ -2291,35 +2291,32 @@
            (end)
-%5Cn%22
 %0A            + %22
@@ -2304,35 +2304,32 @@
 nd)%0A            
-+ %22
     (end)%5Cn%22%0A   
@@ -2313,35 +2313,32 @@
            (end)
-%5Cn%22
 %0A            + %22
@@ -2330,37 +2330,31 @@
             
-+ %22
   (end)
-%5Cn%22
 %0A           
@@ -2350,34 +2350,44 @@
             
-+ %22
 (end)
-%5Cn
+%0A            %22%22
 %22, streamWri
@@ -3138,16 +3138,31 @@
 Equals(%22
+%22%22%0A            
 (bar)foo
@@ -3169,19 +3169,16 @@
 (choice)
-%5Cn%22
 %0A       
@@ -3182,19 +3182,16 @@
         
-+ %22
   (bar)b
@@ -3195,35 +3195,32 @@
 r)bar(container)
-%5Cn%22
 %0A            + %22
@@ -3212,27 +3212,24 @@
             
-+ %22
     (bar)baz
@@ -3239,19 +3239,16 @@
 ntainer)
-%5Cn%22
 %0A       
@@ -3252,19 +3252,16 @@
         
-+ %22
     (end
@@ -3257,27 +3257,24 @@
        (end)
-%5Cn%22
 %0A           
@@ -3278,21 +3278,15 @@
     
-+ %22
   (end)
-%5Cn%22
 %0A   
@@ -3298,18 +3298,28 @@
     
-+ %22
 (end)
-%5Cn
+%0A            %22%22
 %22, s

Use text blocks in YT1433Test