[gedit] Fix newline detection and add more unit tests.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit] Fix newline detection and add more unit tests.
- Date: Mon, 8 Feb 2010 18:54:03 +0000 (UTC)
commit 9fca7e057e12b7595487d52a1f6906f19a5fc58e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Feb 8 19:53:39 2010 +0100
Fix newline detection and add more unit tests.
gedit/gedit-document-output-stream.c | 12 ++----------
tests/document-output-stream.c | 27 ++++++++++++++++++++++-----
2 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/gedit/gedit-document-output-stream.c b/gedit/gedit-document-output-stream.c
index 898df54..d48ce61 100644
--- a/gedit/gedit-document-output-stream.c
+++ b/gedit/gedit-document-output-stream.c
@@ -136,9 +136,6 @@ get_newline_type (GtkTextIter *end)
copy = *end;
c = gtk_text_iter_get_char (©);
- GtkTextIter tt = copy;
- gtk_text_iter_forward_chars (&tt, 2);
-
if (g_unichar_break_type (c) == G_UNICODE_BREAK_CARRIAGE_RETURN)
{
if (gtk_text_iter_forward_char (©) &&
@@ -177,13 +174,8 @@ gedit_document_output_stream_detect_newline_type (GeditDocumentOutputStream *str
type = GEDIT_DOCUMENT_NEWLINE_TYPE_DEFAULT;
- gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->doc), &iter);
-
- if (!gtk_text_iter_backward_line (&iter))
- {
- gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->doc),
- &iter);
- }
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->doc),
+ &iter);
if (gtk_text_iter_ends_line (&iter) || gtk_text_iter_forward_to_line_end (&iter))
{
diff --git a/tests/document-output-stream.c b/tests/document-output-stream.c
index 57b6db5..85a30d8 100644
--- a/tests/document-output-stream.c
+++ b/tests/document-output-stream.c
@@ -30,7 +30,8 @@
static void
test_consecutive_write (const gchar *inbuf,
const gchar *outbuf,
- gsize write_chunk_len)
+ gsize write_chunk_len,
+ GeditDocumentNewlineType newline_type)
{
GeditDocument *doc;
GOutputStream *out;
@@ -38,6 +39,7 @@ test_consecutive_write (const gchar *inbuf,
gssize n, w;
GError *err = NULL;
gchar *b;
+ GeditDocumentNewlineType type;
doc = gedit_document_new ();
out = gedit_document_output_stream_new (doc);
@@ -59,6 +61,9 @@ test_consecutive_write (const gchar *inbuf,
g_assert_cmpstr (inbuf, ==, b);
g_free (b);
+ type = gedit_document_output_stream_detect_newline_type (GEDIT_DOCUMENT_OUTPUT_STREAM (out));
+ g_assert (type == newline_type);
+
g_output_stream_close (out, NULL, &err);
g_assert_no_error (err);
@@ -73,20 +78,32 @@ test_consecutive_write (const gchar *inbuf,
static void
test_empty ()
{
- test_consecutive_write ("", "", 10);
+ test_consecutive_write ("", "", 10, GEDIT_DOCUMENT_NEWLINE_TYPE_DEFAULT);
+ test_consecutive_write ("\r\n", "", 10, GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF);
+ test_consecutive_write ("\r", "", 10, GEDIT_DOCUMENT_NEWLINE_TYPE_CR);
+ test_consecutive_write ("\n", "", 10, GEDIT_DOCUMENT_NEWLINE_TYPE_LF);
}
static void
test_consecutive ()
{
- test_consecutive_write ("hello\nhow\nare\nyou", "hello\nhow\nare\nyou", 2);
+ test_consecutive_write ("hello\nhow\nare\nyou", "hello\nhow\nare\nyou", 2,
+ GEDIT_DOCUMENT_NEWLINE_TYPE_LF);
+ test_consecutive_write ("hello\rhow\rare\ryou", "hello\rhow\rare\ryou", 2,
+ GEDIT_DOCUMENT_NEWLINE_TYPE_CR);
+ test_consecutive_write ("hello\r\nhow\r\nare\r\nyou", "hello\r\nhow\r\nare\r\nyou", 2,
+ GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF);
}
static void
test_consecutive_tnewline ()
{
- test_consecutive_write ("hello\nhow\nare\nyou\n", "hello\nhow\nare\nyou", 2);
- test_consecutive_write ("hello\r\nhow\r\nare\r\nyou\r\n", "hello\r\nhow\r\nare\r\nyou", 2);
+ test_consecutive_write ("hello\nhow\nare\nyou\n", "hello\nhow\nare\nyou", 2,
+ GEDIT_DOCUMENT_NEWLINE_TYPE_LF);
+ test_consecutive_write ("hello\rhow\rare\ryou\r", "hello\rhow\rare\ryou", 2,
+ GEDIT_DOCUMENT_NEWLINE_TYPE_CR);
+ test_consecutive_write ("hello\r\nhow\r\nare\r\nyou\r\n", "hello\r\nhow\r\nare\r\nyou", 2,
+ GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF);
}
int main (int argc,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]