⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringutilstest.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
字号:
/*
 * Created on 03/09/2005
 */
package org.python.pydev.core.docutils;

import junit.framework.TestCase;

public class StringUtilsTest extends TestCase {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(StringUtilsTest.class);
    }

    public void testFormat() {
        assertEquals("teste", StringUtils.format("%s", new Object[]{"teste"}));
        assertEquals("teste 1", StringUtils.format("%s 1", new Object[]{"teste"}));
        assertEquals("%", StringUtils.format("%", new Object[]{}));
    }
    
    
    public void testReplaceAllSlashes() throws Exception {
    	assertEquals("foo", StringUtils.replaceAllSlashes("foo"));
    	assertEquals("foo/", StringUtils.replaceAllSlashes("foo\\"));
    	assertEquals("/foo/", StringUtils.replaceAllSlashes("\\foo\\"));
    	assertEquals("/foo///", StringUtils.replaceAllSlashes("\\foo\\\\\\"));
		
	}
    
    public void testReplaceAll() throws Exception {
        assertEquals("foo", StringUtils.replaceAll("fjj", "j", "o"));
        assertEquals("fok", StringUtils.replaceAll("fkkkk", "kkk", "o"));
        assertEquals("foo", StringUtils.replaceAll("fkkkk", "kk", "o"));
        assertEquals("kkkkkkkkk", StringUtils.replaceAll("www", "w", "kkk"));
        assertEquals("www", StringUtils.replaceAll("www", "o", "a"));
        
        String initial = ""+
        "import sys; sys.ps1=''; sys.ps2=''\r\n"+
        "print >> sys.stderr, 'PYTHONPATH:'\r\n"+
        "for p in sys.path:\r\n"+
        "    print >> sys.stderr,  p\r\n" +
        "\r\n" +                                                //to finish the for scope
        "print >> sys.stderr, 'Ok, all set up... Enjoy'\r\n"+
        "";
        assertEquals(initial, StringUtils.replaceAll(initial, "\r\n", "\r\n"));
        
        String expected = ""+
        "import sys; sys.ps1=''; sys.ps2=''\r"+
        "print >> sys.stderr, 'PYTHONPATH:'\r"+
        "for p in sys.path:\r"+
        "    print >> sys.stderr,  p\r" +
        "\r" +                                                //to finish the for scope
        "print >> sys.stderr, 'Ok, all set up... Enjoy'\r"+
        "";
        assertEquals(expected, StringUtils.replaceAll(initial, "\r\n", "\r"));
    }
    
    public void testRemoveWhitespaceColumnsToLeft() throws Exception {
        assertEquals("foo", StringUtils.removeWhitespaceColumnsToLeft("   foo"));
        assertEquals("foo\n", StringUtils.removeWhitespaceColumnsToLeft("   foo\n"));
        assertEquals("foo\n   foo\n", StringUtils.removeWhitespaceColumnsToLeft(" foo\n    foo\n"));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -