[vala/0.54] tests: Add "instance access to implicit to_string() method of enum" test



commit 57f1f4160c292c80e08e74e9b3ffd3df34ebdc6c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Oct 18 09:19:07 2021 +0200

    tests: Add "instance access to implicit to_string() method of enum" test

 tests/Makefile.am                |  1 +
 tests/enums/bug614424.c-expected | 85 ++++++++++++++++++++++++++++++++++++++++
 tests/enums/bug614424.vala       | 11 ++++++
 3 files changed, 97 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 904ae9739..3ea602a23 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -335,6 +335,7 @@ TESTS = \
        enums/in-invalid.test \
        enums/no_gtype_to_string.vala \
        enums/switch.vala \
+       enums/bug614424.vala \
        enums/bug666035.vala \
        enums/bug666035-1.test \
        enums/bug666035-2.test \
diff --git a/tests/enums/bug614424.c-expected b/tests/enums/bug614424.c-expected
new file mode 100644
index 000000000..d769d657d
--- /dev/null
+++ b/tests/enums/bug614424.c-expected
@@ -0,0 +1,85 @@
+/* enums_bug614424.c generated by valac, the Vala compiler
+ * generated from enums_bug614424.vala, do not modify */
+
+#include <glib-object.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+typedef enum  {
+       FOO_BAR
+} Foo;
+
+#define TYPE_FOO (foo_get_type ())
+#define _g_free0(var) (var = (g_free (var), NULL))
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning 
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+
+VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
+VALA_EXTERN gchar* foo_bar (Foo self);
+static void _vala_main (void);
+
+gchar*
+foo_bar (Foo self)
+{
+       GEnumValue* _tmp0_;
+       gchar* _tmp1_;
+       gchar* result = NULL;
+       _tmp0_ = g_enum_get_value (g_type_class_ref (TYPE_FOO), self);
+       _tmp1_ = g_strdup ((_tmp0_ != NULL) ? _tmp0_->value_name : NULL);
+       result = _tmp1_;
+       return result;
+}
+
+static GType
+foo_get_type_once (void)
+{
+       static const GEnumValue values[] = {{FOO_BAR, "FOO_BAR", "bar"}, {0, NULL, NULL}};
+       GType foo_type_id;
+       foo_type_id = g_enum_register_static ("Foo", values);
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__volatile = 0;
+       if (g_once_init_enter (&foo_type_id__volatile)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__volatile, foo_type_id);
+       }
+       return foo_type_id__volatile;
+}
+
+static void
+_vala_main (void)
+{
+       gchar* _tmp0_;
+       gchar* _tmp1_;
+       _tmp0_ = foo_bar (FOO_BAR);
+       _tmp1_ = _tmp0_;
+       _vala_assert (g_strcmp0 (_tmp1_, "FOO_BAR") == 0, "Foo.BAR.bar () == \"FOO_BAR\"");
+       _g_free0 (_tmp1_);
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/enums/bug614424.vala b/tests/enums/bug614424.vala
new file mode 100644
index 000000000..7312eed0b
--- /dev/null
+++ b/tests/enums/bug614424.vala
@@ -0,0 +1,11 @@
+enum Foo {
+       BAR;
+
+       public string bar () {
+               return to_string ();
+       }
+}
+
+void main () {
+       assert (Foo.BAR.bar () == "FOO_BAR");
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]