/*
 * Copyright (C) 2012 Brian Muramatsu
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.btmura.android.reddit.text;

public class MarkdownFormatter_NamedLinksTest extends AbstractFormatterTest {

    public void testFormat() {
        CharSequence cs = assertNamedLinksFormat("[foo](abc)", "foo");
        assertUrlSpan(cs, 0, 3, "http://abc");

        cs = assertNamedLinksFormat("[foo] (abc)", "foo");
        assertUrlSpan(cs, 0, 3, "http://abc");

        cs = assertNamedLinksFormat("[foo] (abc desc)", "foo");
        assertUrlSpan(cs, 0, 3, "http://abc");

        cs = assertNamedLinksFormat("[foo]\n(abc desc)", "foo");
        assertUrlSpan(cs, 0, 3, "http://abc");

        cs = assertNamedLinksFormat("[foo\n](abc desc)", "foo\n");
        assertUrlSpan(cs, 0, 3, "http://abc");
    }

    public void testFormat_nestedBrackets() {
        CharSequence cs = assertNamedLinksFormat("[[link]](/abc)", "[link]");
        assertUrlSpan(cs, 0, 6, "http://www.reddit.com/abc");
    }

    public void testFormat_nestedBrackets2() {
        CharSequence cs = assertNamedLinksFormat("[[a]](/a) [[b]](/b)", "[a] [b]");
        assertUrlSpan(cs, 0, 3, "http://www.reddit.com/a");
        assertUrlSpan(cs, 4, 7, "http://www.reddit.com/b");
    }

    public void testFormat_nestedBrackets3() {
        CharSequence cs = assertNamedLinksFormat("[[a](/a)]", "[a]");
        assertUrlSpan(cs, 0, 3, "http://www.reddit.com/a");
    }

    public void testFormat_nestedParens() {
        CharSequence cs = assertNamedLinksFormat("Here is a [link](/abc (123) (456)).",
                "Here is a link.");
        assertUrlSpan(cs, 10, 14, "http://www.reddit.com/abc");
    }

    public void testFormat_nestedParens2() {
        CharSequence cs = assertNamedLinksFormat("[abc (def)](/abc (123) (456))", "abc (def)");
        assertUrlSpan(cs, 0, 9, "http://www.reddit.com/abc");
    }

    public void testFormat_multiple() {
        CharSequence cs = assertNamedLinksFormat("[Link 1](/a (123)) and [Link 2](/b (456))",
                "Link 1 and Link 2");
        assertUrlSpan(cs, 0, 6, "http://www.reddit.com/a");
        assertUrlSpan(cs, 11, 17, "http://www.reddit.com/b");
    }

    public void testFormat_nestedParensMultipleLines() {
        CharSequence cs = assertNamedLinksFormat("[Link 1](/a (123))\n[Link 2](/b (456))",
                "Link 1\nLink 2");
        assertUrlSpan(cs, 0, 6, "http://www.reddit.com/a");
        assertUrlSpan(cs, 7, 13, "http://www.reddit.com/b");
    }
}

@@ -1474,32 +1474,33 @@
 (cs, 0, 6, %22http
+s
 ://www.reddit.co
@@ -1500,32 +1500,32 @@
 ddit.com/abc%22);%0A
-
     %7D%0A%0A    publi
@@ -1675,32 +1675,33 @@
 (cs, 0, 3, %22http
+s
 ://www.reddit.co
@@ -1736,32 +1736,33 @@
 (cs, 4, 7, %22http
+s
 ://www.reddit.co
@@ -1921,32 +1921,33 @@
 (cs, 0, 3, %22http
+s
 ://www.reddit.co
@@ -2163,24 +2163,25 @@
 0, 14, %22http
+s
 ://www.reddi
@@ -2374,24 +2374,25 @@
  0, 9, %22http
+s
 ://www.reddi
@@ -2612,32 +2612,33 @@
 (cs, 0, 6, %22http
+s
 ://www.reddit.co
@@ -2679,24 +2679,25 @@
 1, 17, %22http
+s
 ://www.reddi
@@ -2930,24 +2930,25 @@
  0, 6, %22http
+s
 ://www.reddi
@@ -2992,24 +2992,25 @@
 7, 13, %22http
+s
 ://www.reddi

Fix broken test to use https urls